在Matlab中读'uint8'比读'double'更快?

时间:2018-08-10 03:59:01

标签: matlab io fread

我正在尝试提高大型磁盘读取操作的性能。

Apparently, reading in uint8 and then typecasting to double is faster than reading directly in double.

我尝试重现此问题,但是与doubleuint的性能相同。这是我的两种情况的代码。我在做什么错了?

N=16800; %my matrices are quite large

%the file contains a 1 x N^2 double vector
fid = fopen('myfile.bin', 'r');

%using *uint and casting
tic
matrix1=fread(fid,8*N^2, '*uint8');
matrix1=typecast(matrix1,'double');
toc

%using double straight away
tic
matrix2=fread(fid,N^2,'double');
toc

fclose(fid);

时间实际上是相同的。为什么uint8会更快?

Elapsed time is 1.975456 seconds.
Elapsed time is 2.077142 seconds.

编辑:正如@ Rahnema1指出的那样,以上示例存在一个错误。 fseek应该用于返回文件的开头。 编辑:正如@Cris Luengo指出的那样,该链接针对包含混合数据类型的文件提出了建议,因此这不适用于我的情况。

0 个答案:

没有答案