我试图在MATLAB FileExchange上使用savefast函数。我注意到它在我的设置上的表现并不一致。当我运行以下代码时,我得到以下时间。第4次注意,它花了20倍的时间!通常每10个慢速运行2到5个,随机分布(有时连续3个慢)。变化完全在低级别H5ML.hdf5lib2函数中。
我已经在4台不同的机器上试过了。其中2个(Server 2008 R2,Windows 7),我看到下面的狂野变化。另外2个(Server 2008,Server 2012),几乎没有变化。 2 Server 2008机箱具有相同的硬件,防病毒,几乎没有运行它们。所以问题是机器特定的。但是,所有的盒子都是相对强大的64位,所以我认为这个问题不应该发生。是否有一些棘手的低级设置使HDF5更加一致地工作?
当我尝试使用save
或fwrite
命令而不是下面的代码时,时间几乎没有变化,这让我觉得这是HDF5特定的问题。
clear classes;
delete('test_*.mat');
x = rand(10000, 1000);
%%
disp('Using h5write:');
for j = 1:10
% make new file
fname = sprintf('test_h5_%d.mat', j);
dummy = 0;
save(fname, '-v7.3', 'dummy');
varname = '/x';
h5create(fname, varname, size(x), 'DataType', class(x));
tic;
h5write(fname, varname, x);
toc;
end
disp('Using save:');
for j = 1:10
tic;
fname = sprintf('test_save_%d.mat', j);
save(fname, 'x');
toc;
end
disp('Using fwrite:');
for j = 1:10
tic;
fname = sprintf('test_fwrite_%d.mat', j);
fileID = fopen(fname,'w');
fwrite(fileID, x, 'double');
fclose(fileID);
toc;
end
disp('Using memory map:');
for j = 1:10
tic;
fname = sprintf('test_fwrite_%d.mat', j);
m = memmapfile(fname, ...
'Format','double');
m.Writable = true;
m.Data = x;
toc;
end
clear m;
输出上述代码:
>>
Using h5write:
Elapsed time is 0.120691 seconds.
Elapsed time is 0.123445 seconds.
Elapsed time is 0.109917 seconds.
Elapsed time is 2.773781 seconds.
Elapsed time is 0.104730 seconds.
Elapsed time is 0.115631 seconds.
Elapsed time is 0.106282 seconds.
Elapsed time is 0.119643 seconds.
Elapsed time is 0.109200 seconds.
Elapsed time is 0.110083 seconds.
Using save:
Elapsed time is 2.774994 seconds.
Elapsed time is 2.776656 seconds.
Elapsed time is 2.777405 seconds.
Elapsed time is 2.811365 seconds.
Elapsed time is 2.780027 seconds.
Elapsed time is 2.775661 seconds.
Elapsed time is 2.776308 seconds.
Elapsed time is 2.800510 seconds.
Elapsed time is 2.783472 seconds.
Elapsed time is 2.782114 seconds.
Using fwrite:
Elapsed time is 0.035606 seconds.
Elapsed time is 0.094308 seconds.
Elapsed time is 0.033619 seconds.
Elapsed time is 0.034147 seconds.
Elapsed time is 0.033776 seconds.
Elapsed time is 0.034627 seconds.
Elapsed time is 0.033806 seconds.
Elapsed time is 0.035084 seconds.
Elapsed time is 0.034562 seconds.
Elapsed time is 0.039331 seconds.
Using memory map:
Elapsed time is 0.079036 seconds.
Elapsed time is 0.035585 seconds.
Elapsed time is 0.035654 seconds.
Elapsed time is 0.036398 seconds.
Elapsed time is 0.035054 seconds.
Elapsed time is 0.039047 seconds.
Elapsed time is 0.036286 seconds.
Elapsed time is 0.035016 seconds.
Elapsed time is 0.036145 seconds.
Elapsed time is 0.036497 seconds.
ver命令的输出:
>> ver
----------------------------------------------------------------------------------------------------
MATLAB Version: 8.2.0.701 (R2013b)
MATLAB License Number: xxxxxx
Operating System: Microsoft Windows Server 2008 R2 Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------
MATLAB Version 8.2 (R2013b)
Database Toolbox Version 5.0 (R2013b)
Statistics Toolbox Version 8.3 (R2013b)
更新 我试过了: