Desktop Tools and Development Environment Previous page   Next Page

Profiling Process Guidelines

Here is a general process you can follow to use the Profiler to improve performance in your M-files. This section also describes how you can use profiling as a debugging tool and as a way to understand complex M-files.

  1. In the summary report produced by the Profiler, look for functions that used a significant amount of time or were called most frequently. See Profile Summary Report for more information.
  2. View the detail report produced by the Profiler for those functions and look for the lines that use the most time or are called most often. See Profile Detail Report for more information.
  1. You might want to keep a copy of your first detail report to use as a reference to compare with after you make changes, and then profile again.

  1. Determine whether there are changes you can make to the lines most called or the most time-consuming lines to improve performance.
  1. For example, if you have a load statement within a loop, load is called every time the loop is called. You might be able to save time by moving the load statement so it is before the loop and therefore is only called once.

  1. Click the links to the files and make the changes you identified for potential performance improvement. Save the files and run clear all. Run the Profiler again and compare the results to the original report. Note that there are inherent time fluctuations that are not dependent on your code. If you profile the exact same code twice, you can get slightly different results each time.
  2. Repeat this process to continue improving the performance.

Using Profiling as a Debugging Tool

The Profiler is a useful tool for isolating problems in your M-files.

For example, if a particular section of the file did not run, you can look at the detail reports to see what lines did run, which might point you to the problem.

You can also view the lines that did not run to help you develop test cases that exercise that code.

If you get an error in the M-file when profiling, the Profiler provides partial results in the reports. You can see what ran and what did not to help you isolate the problem. Similarly, you can do this if you stop the execution using Ctrl+C, which might be useful when a file is taking much more time to run than expected.

Using Profiling for Understanding an M-File

For lengthy M-files that you did not create or that you have not used for awhile and are unfamiliar with, you can use the Profiler to see how the M-file actually worked. Use the Profiler detail reports to see the lines actually called.

If there is an existing GUI tool (or M-file) similar to one that you want to create, start profiling, use the tool, then stop profiling. Look through the Profiler detail reports to see what functions and lines ran. This helps you determine the lines of code in the file that are most like the code you want to create.


Previous page  What Is Profiling? The Profiler Next page

© 1994-2005 The MathWorks, Inc.