Programming and Data Types    

What Is Profiling?

Profiling is a way to measure where a program spends its time. You can deal with obvious speed issues at design time and can then discover unanticipated effects through measurement. One key to effective coding is to create a first implementation that is as simple as possible, and then to use a profiler to identify bottlenecks if speed is an issue. Premature optimization often increases code complexity unnecessarily without providing a real gain in performance.

Use the MATLAB Profiler to identify statements that are not taking advantage of the MATLAB tools described in Performance Acceleration. You may then be able to modify your statements to take advantage of these performance acceleration tools.

Also use the MATLAB Profiler to identify functions that consume the most time, then determine why you are calling them and look for ways to minimize their use. It is often helpful to decide whether the number of times a particular function is called is reasonable. Because programs often have several layers, your code may not explicitly call the most time-consuming functions. Rather, functions within your code might be calling other time-consuming functions that can be several layers down in the code. In this case it is important to determine which of your functions are responsible for such calls.

The Profiler often helps to uncover performance problems that you can solve by

When you reach the point where most of the time is spent on calls to a small number of built-in functions, you have probably optimized the code as much as you can expect.

  Measuring Performance The Profiler