At the operating system level, using a memory-mapped file is faster than using standard I/O functions. However, there is some additional overhead incurred in using the MEMMAPFILE object within MATLAB.
With MEMMAPFILE, there is an overhead penalty associated with every access of the Data member of this class. Therefore you will likely not see improved performance when reading or writing a small number of values in a single assignment to a memory mapped file when compared to FWRITE.
To work around this issue, you can create a reference to the "Data" property, which cuts down on some overhead when accessing data. The following code using memory-mapped files should run faster than using standard I/O functions:
m = memmapfile ('myfile.dat', 'Format', 'double' );
dataRef = m.Data;
for k = 1 : N
y(k) = dataRef (k);
end
The general rules and techniques for vectorization of code apply even more so to MEMMAPFILE objects. You can find details regarding vectorization here:
Techniques to improve performance (MATLAB Programming):
More information on memory mapped files in MATLAB is available here:
Accessing Files with Memory-Mapping :: Data Import and Export (MATLAB Programming)
Best Answer