回 帖 发 新 帖 刷新版面

主题:[讨论]matlab程序运行时间测试

大家知道,matlab 中使用
            TIC
              operations
              TOC
来测试 operations 所耗时间
但是我编写一个tt1.m:
tic
for i=1:5
    for j=1:10000
        H(i,j)=1/(i+j-1);
    end
end
toc
进行测试,发现每次运行的所耗时间相差非常大(结果如下),不知道什么原因??

回复列表 (共2个回复)

沙发


我试了一下,每次运行差不了多少时间。如果要是差距比较大,可能是前面的变量对后面的有影响,或是没有预分配矩阵空间。
tic
H=ones(5,10000);
for i=1:5
    for j=1:10000
        H(i,j)=1/(i+j-1);
    end
end
toc

板凳

我 机子上运行结果:
>> tt1
Elapsed time is 0.000000 seconds.
>> tt1
Elapsed time is 0.000000 seconds.
>> tt1
Elapsed time is 0.015000 seconds.
>> tt1
Elapsed time is 0.000000 seconds.
>> tt1
Elapsed time is 0.015000 seconds.
>> 
一会儿是 0.000000 seconds,一会儿是 0.015000 seconds.

我来回复

您尚未登录,请登录后再回复。点此登录或注册