MATLAB Profiling Lien-Chi Lai, COLA Lab 2010/05/06
Outline Tic & toc Clock Etime Profile
Tic & Toc MATLAB Profiling3 tic – Start a stopwatch timer toc – Read the stopwatch timer tic and toc function work together to measure elapsed time between the two Sample: Tic & Toc >> tic; % Start stopwatch >> inv(rand(500)); % Matrix inverse >> toc; % Stop and measure elapsed time
Clock MATLAB Profiling4 Returns current date and time as a vector The vector is in a decimal form contains six element [year month day hour minute seconds] Sample : Clock >> fix(clock); % Rounds to integer display format ans =
Etime MATLAB Profiling5 etime(t1, t0) returns the time in seconds that has elapsed between vectors t1 and t0 t0 and t1 must be the format returned by clock Sample : Etime >> t0 = clock; % Record initial time >> inv(rand(500)); % Matrix inverse >> t1 = clock; % Record final time >> etime(t1, t0); % Measure elapsed time
Profile MATLAB Profiling6 Returns summary of function calls and total time Sample : profile_test.m Profile % 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
Profile – GUI MATLAB Profiling7 As an alternative to the profile function select Desktop > Profiler to open the Profiler click the “Profiler” button do not include “.m” in the “Run this code” field Profile - GUI
Other Resources MATLAB Profiling8 filer-to-find-code-bottlenecks/ Profile - GUI