【1】tic,toc %这方法最简单,但一定要一起执行,
tic %否则显示的是tic和toc两条命令的间隔时间
your_operation
toc
【2】cputime %给一个变量设定为cputime,做操作,然后看这个时间变了多少,
t=cputime; % 但如果时间太小就显示0
your_operation
cputime-t
【3】clock,etime %和上面类似
t0 = clock;
your_operation
etime(clock,t0)
【4】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