
603I/O Techniques
end
fclose(fid);
⇨ Elapsed time is 8.685103 seconds.
% Using bulk I/O - 170x faster (non-vectorized)
fid = fopen('test.dat');
data = fread(fid,inf,'double');
for idx = 1 : 1e6
data(idx) = sqrt(data(idx));
end
fclose(fid);
⇨ Elapsed time is 0.050718 seconds.
When reading data from an external hardware interface (e.g., an instrument or hardware
device connected via USB or serial port), rather than a le, it makes sense to use buffering.
1699
Using data buffers help to process data in chunks, rather than each data element separately
as it arrives. In essence, data buffering mimics the I/O consolidation recommendation abov ...