MATLAB Function Reference    

Tool for optimizing and debugging M-file code

Graphical Interface

As an alternative to the profile function, select View -> Profiler from the desktop.



The profile function helps you debug and optimize M-files by tracking their execution time. For each function in the M-file, profile records information about execution time, number of calls, parent functions, child functions, code line hit count, and code line execution time. Some people use profile simply to see the child functions; see also depfun for that purpose. The Profiler user interface, opened with profile viewer, provides information gathered using the profile function, but presents the information in a different format from profile report.

profile viewer opens the Profiler graphical interface, a tool for assessing M-file performance to help you identify potential performance improvements. It is based on the results returned by the profile function, but presents the information a different format than the profile report. The report function provides some options not available with the Profiler, including saving the reports to a file.

profile on starts profile, clearing previously recorded profile statistics.

profile on -detail level starts profile for the set of functions specified by level, clearing previously recorded profile statistics.

Value for level
Functions profile Gathers Information About
M-functions, M-subfunctions, and MEX-functions; mmex is the default value
Same functions as for mmex plus built-in functions such as eig
Same functions as for builtin plus built-in operators such as +

profile on -history starts profile, clearing previously recorded profile statistics, and recording the exact sequence of function calls. The profile function records up to 10,000 function entry and exit events. For more than 10,000 events, profile continues to record other profile statistics, but not the sequence of calls.

profile off suspends profile.

profile resume restarts profile without clearing previously recorded statistics.

profile clear clears the statistics recorded by profile.

profile report suspends profile, generates a profile report in HTML format, and displays the report in your system's default Web browser. This report contains some different information than what is available in the Profiler reports.

profile report basename suspends profile, generates a profile report in HTML format, saves the report in the file basename in the current directory, and displays the report in your system's default Web browser. Because the report consists of several files, do not provide an extension for basename.

profile plot suspends profile and displays in a figure window a bar graph of the functions using the most execution time.

s = profile('status') displays a structure containing the current profile status. The structure's fields are

'on' or 'off'
'mmex', 'builtin', or 'operator'
'on' or 'off'

stats = profile('info') suspends profile and displays a structure containing profile results. Use this function to access the data generated by profile. The structure's fields are

Array containing list of all functions called
Array containing function call history
Precision of profile's time measurement


To see an example of a profile report and profile plot, as well as to learn more about the results and how to use profiling, see Measuring Performance" and "The profile Function" in MATLAB Programming documentation.


Follow these steps to run profile and create a profile report.

  1. Run profile for code that computes the Lotka-Volterra predator-prey population model.
  1. The profile report appears in your system's default Web browser, providing information for all M-functions, M-subfunctions, MEX-functions, and built-in functions. The report includes the function call history.

  1. Generate the profile plot.
  1. The profile plot appears in a figure window.

  1. Because the report and plot features suspend profile, resume its operation without clearing the statistics already gathered.
  1. The profile function continues gathering statistics when you execute the next M-file.

See Also

depdir, depfun, profreport, tic

See "Measuring Performance, The Profiler, and The profile Function in the MATLAB Programming documentation.

  prod profreport