用MATLAB精确测量算法运行时间

时间:2016-01-03 16:25:31

标签: algorithm matlab time execution

我正在尝试测量下面代码的运行时间。

function out=load_database()

    persistent loaded;
    persistent w;
    if(isempty(loaded))

    A=zeros(10304,400);
    for i=1:40
        cd(strcat('s',num2str(i)));
        for j=1:8
            a=imread(strcat(num2str(j),'.pgm'));
            A(:,(i-1)*8+j)=reshape(a,size(a,1)*size(a,2),1); 
        end 
        cd ..
     end
     w=A;
     end

     loaded=1;
     out=w;
end

我尝试使用tictoc,但由于测量结果不正常 时间就像2-3秒,实际上它需要将近20秒,直到一切都完成。

此代码适用于ORL数据库:http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html 它只加载10个图像中的8个。 8用于培训,另外2用于测试。不是最好的方式,但对我来说没问题。

0 个答案:

没有答案
相关问题