Installation guide

7 Tuning and Managing M-Files
Profiling Process and 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 debuggin g t ool and as a way to understand complex M-file s.
Note Premature optimization can increase code complexity unnecessarily
without providing a real gain in performance. Your first implementation
should be as simple as possible. Then, if spee d is an issue, use prof il ing to
identify bottlenecks.
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” on page 7-33 for m ore information.
2 View the detail r eport produce d by the Profiler fo r those functions and lo ok
for the lines that use the most time or are called most often. See “Profile
Detail Report” on page 7-35 for more information.
Yo u might want to keep a copy o f your first detail report to use as a
reference to compare with after y ou make changes, and then profile again.
3 Determinewhethertherearechangesyoucanmaketothelinesmostcalled
or the most time-consuming lines to improve performance.
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.
4 Click the links to the files a nd make the changes you identified for potential
performance improvement. Save the files and run
clear all.Runthe
Profiler again and compare the results to the original report. Note tha t
there are inherent time fluctuations that are not de pe ndent on your code.
If you profile the exact s ame code twice, you can get slightly d iffe rent
results each time.
5 Repeat this process to continue improving the pe rformance.
7-28