-
MATLAB中测试程序运行时间的函数
日期:2009-06-20 | 分类:matlab |
1. profile
例子:
profile on
plot(magic(35))
profile viewer
profsave(profile('info'),'profile_results')
profile on -history
plot(magic(4));
p = profile('info');
for n = 1:size(p.FunctionHistory,2)
if p.FunctionHistory(1,n)==0
str = 'entering function: ';
else
str = ' exiting function: ';
end
disp([str p.FunctionTable(p.FunctionHistory(2,n)).FunctionName]);
end
2. tic,toc
ticoperation
toc
3. cputime
t=cputime;your_operation
cputime-t
4. clock,etime
t0 = clock;
operation
etime(clock,t0)以上转载自 http://bittermelon.blogbus.com/logs/22837185.html
--------------------------------------------------------------------------------
note:
1.Profile time is CPU time. The total time reported by the Profiler is not the same as the time reported using the tic and toc functions or the time you would observe using a stopwatch.
2.toc 记录的是自上面最近的一个tic开始的时间!
3.toc time=cpu time + other time ( pause function etc.)
4. Although it is possible to measure performance using the cputime function, it is recommended that you use the tic and toc functions for this purpose exclusively. See Using tic and toc Versus the cputime Function in the MATLAB Programming documentation for more information.
5. When timing the duration of an event, use the tic and toc functions instead of clock or etime. These latter two functions are based on the system time which can be adjusted periodically by the operating system and thus might not be reliable in time comparison operations.