February 2019
Intermediate to advanced
672 pages
16h 50m
English
Now that we have identified where exactly our application is spending most of its time, we can make some changes and assess the change in performance.
There are different ways to tune up our pure Python code. The way that produces the most remarkable results is to improve the algorithms used. In this case, instead of calculating the velocity and adding small steps, it will be more efficient (and correct as it is not an approximation) to express the equations of motion in terms of radius, r, and angle, alpha, (instead of x and y), and then calculate the points on a circle using the following equation:
x = r * cos(alpha) y = r * sin(alpha)
Another way lies in minimizing the number of instructions. For example, we can precalculate ...