
64 Accelerating MATLAB
®
Performance
3.1.2 Minimize Function Call Overheads
Calling functions incurs a nonnegligible overhead, especially when done repeatedly within
a loop.* The effect is especially important when calling functions (methods) of object-ori-
ented classes or external objects such as COM or Java, when the loop iteration time is very
small (several milliseconds or less), and when the loop runs numerous iterations. By mini-
mizing function calls within the iterations, we can sometimes achieve signicant speedups.
When developing programs, avoid creating numerous tiny functions that call each
other, a design antipattern that is someti ...