This document discusses various tools for profiling MATLAB code: tic and toc to measure elapsed time between points; clock to get the current date and time; etime to measure time between two clock vectors; profile to get a summary of function calls and times; and the profiler GUI as an alternative to the profile function.
This document discusses various tools for profiling MATLAB code: tic and toc to measure elapsed time between points; clock to get the current date and time; etime to measure time between two clock vectors; profile to get a summary of function calls and times; and the profiler GUI as an alternative to the profile function.
This document discusses various tools for profiling MATLAB code: tic and toc to measure elapsed time between points; clock to get the current date and time; etime to measure time between two clock vectors; profile to get a summary of function calls and times; and the profiler GUI as an alternative to the profile function.
2010/05/06
Outline
Tic
&
toc
Clock
EAme
Profile
Tic
&
Toc
tic
–
Start
a
stopwatch
Amer
toc
–
Read
the
stopwatch
Amer
tic
and
toc
funcAon
work
together
to
measure
elapsed
Ame
between
the
two
Sample:
>> tic; % Start stopwatch >> inv(rand(500)); % Matrix inverse >> toc; % Stop and measure elapsed time
3
MATLAB
Profiling
Tic
&
Toc
Clock
Returns
current
date
and
Ame
as
a
vector
The
vector
is
in
a
decimal
form
contains
six
element
[year
month
day
hour
minute
seconds]
Sample: >> fix(clock); % Rounds to integer display format ans = 2010 5 6 15 53 1
4
MATLAB
Profiling
Clock
EAme
etime(t1, t0)
returns
the
Ame
in
seconds
that
has
elapsed
between
vectors
t1
and
t0 t0
and
t1
must
be
the
format
returned
by
clock Sample: >> t0 = clock; % Record initial time >> inv(rand(500)); % Matrix inverse >> t1 = clock; % Record final time >> etime(t1, t0); % Measure elapsed time
5
MATLAB
Profiling
EAme
Profile
Returns
summary
of
funcAon
calls
and
total
Ame
Sample: profile_test.m % start the profiler and clear previous record profile on
for i=1:10 inv(rand(100)); end
% stop the profiler
profile off
% save profile record as html profile report
profsave(profile('info'), 'profile_results')
profile report % display profile report
6
MATLAB
Profiling
Profile
Profile
–
GUI
As
an
alternaAve
to
the
profile
funcAon
select
Desktop
>
Profiler
to
open
the
Profiler
click
the
“Profiler”
buZon
do
not
include
“.m”
in
the
“Run
this
code”
field
7
MATLAB
Profiling
Profile
-‐
GUI
Other
Resources
http://blogs.mathworks.com/videos/2006/10/19/ profiler-to-find-code-bottlenecks/