You are on page 1of 8

MATLAB

 Profiling  

Lien-­‐Chi  Lai,  COLA  Lab  


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/

8   MATLAB  Profiling   Profile  -­‐  GUI  

You might also like