Profile to Improve Performance
In this section...
“What Is Profiling?” on page 28-5
“Profiling Process and Guidelines” on page 28-5
“Using the Profiler” on page 28-6
“Profile Summary Report” on page 28-8
“Profile Detail Report” on page 28-9
What Is Profiling?
Profiling is a way to measure where a program spends time. After you identify which
functions are consuming the most time, you can evaluate them for possible performance
improvements. Also, you can profile your code as a debugging tool. For example,
determining which lines of code MATLAB does not run can help you develop test cases
that exercise that code. If you get an error in the file when profiling, you can see what ran
and what did not to help you isolate the problem.
TipCode that is prematurely optimized can be unnecessarily complex without providing
a significant gain in performance. Make your first implementation as simple as possible.
Then, if speed is an issue, use profiling to identify bottlenecks.
You can profile your code using the MATLAB Profiler. The Profiler is a user interface
based on the results returned by the profile function. If you are profiling code that runs
in parallel, for best results use the Parallel Computing Toolbox™ parallel profiler. For
details, see “Profiling Parallel Code” (Parallel Computing Toolbox).
Profiling Process and Guidelines
Use this general process to improve performance in your code:
1 Run the Profiler on your code.
2 In the Profile Summary report, look for functions that use a significant amount of
time or that are called most frequently.
3 View the Profile Detail report for those functions, and look for the lines of code that
take the most time or are called most often.
Profile to Improve Performance