Desktop Tools and Development Environment |
Example: Using the profile Function
This example demonstrates how to run profile
:
profile
, type in the Command Window
lotkademo
, which runs a demonstration.
profile
.
profile
, without clearing the existing statistics.
profile
function is now ready to continue gathering statistics for any more M-files you run. It will add these new statistics to those generated in the previous steps.
profile
when you finish gathering statistics.
profile
specifying the 'info'
argument. The profile function returns data in a structure.
p = profile('info') p = FunctionTable: [27x1 struct] FunctionHistory: [2x766 double] ClockPrecision: 1.0000e-007 Name: 'MATLAB' ClockSpeed: 1000
profsave
function. This function stores the profile information in separate HTML files, for each function listed in the FunctionTable
field of the structure, p
.
profsave
puts these HTML files in a subdirectory of the current directory named profile_results
. You can specify another directory name as an optional second argument to profsave
.
Accessing Profiler Results
The profile
function returns results in a structure. This example illustrates how you can access these results:
lotkademo
, which runs a demonstration.
stats = profile('info') stats = FunctionTable: [34x1 struct] FunctionHistory: [2x968 double] ClockPrecision: 1.1111e-007 Name: 'MATLAB' ClockSpeed: 1000
FunctionTable
field is an array of structures, where each structure represents an M-function, M-subfunction, MEX-function, or, because the builtin
option is specified, a MATLAB built-in function.
stats.FunctionTable ans = 41x1 struct array with fields: FunctionName FileName Type NumCalls TotalTime TotalRecursiveTime Children Parents ExecutedLines
FunctionTable
field.
stats.FunctionTable(3) ans = FunctionName: 'ode23' FileName: [1x55 char] Type: 'M-function' NumCalls: 1 TotalTime: 0.6810 TotalRecursiveTime: 0.6810 Children: [11x1 struct] Parents: [0x1 struct] ExecutedLines: [132x4 double] IsRecursive: 0 AcceleratorMessages: {1x0 cell}
FunctionHistory
field. The history data is a 2-by-n array. The first row contains Boolean values where 1
means entrance into a function and 0
(zero) means exit from a function. The second row identifies the function being entered or exited by its index in the FunctionTable
field. To see how to create a formatted display of history data, see the example on the profile
reference page.
Saving Profile Reports
To save the profile report, use the profsave
function.
This function stores the profile information in separate HTML files, for each function listed in the FunctionTable
field of the structure, p
.
profsave(p)
By default, profsave
puts these HTML files in a subdirectory of the current directory named profile_results
. You can specify another directory name as an optional second argument to profsave
.
profsave(p,'mydir')
The profile Function | Publishing Results |
© 1994-2005 The MathWorks, Inc.