Main Content

What Affects Code Execution Speed

Potential Bottlenecks

Performance becomes an issue when working with large amounts of data and large numbers of objects. In such cases, you can improve the execution speed of graphics code by minimizing the effect of two factors that contribute to total execution time:

  • Object creation — Adding new graphics objects to a scene.

  • Screen updates — Updating the graphics model and sending changes to be rendered.

It is often possible to prevent these activities from dominating the total execution time of a particular programming pattern. Think of execution time as being the sum of a number of terms:

T execution time = T creating objects + T updating + (T calculations, etc)

The examples that follow show ways to minimize the time spent in object creation and updating the screen. In the preceding expression, the execution time does not include time spent in the actual rendering of the screen.

How to Improve Performance

Profile your code and optimize algorithms, calculation, and other bottlenecks that are specific to your application. Then determine if the code is taking more time in object creation functions or drawnow (updating). You can begin to optimize both operations, beginning with the larger term in the total time equation.

Is your code: