How does the compression of MAT-files in MATLAB 7.0 (R14) affect performance?

33 views (last 30 days)
I understand that MAT-files in MATLAB 7.0 (R14) are compressed by default. I would like to know how that affects performance.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Nov 2016
Following are some important things to note about compressed MAT-files :
1. You should consider both data set size and the type of data being saved when deciding whether or not to compress the data you save to a file. The benefits of data compression are greater when saving large data sets (over 3MB), and are usually negligible with smaller data sets. Data that has repeating patterns or more consistent values compresses better than random data. Compressing data that has a random pattern is not recommended as it slows down the performance of save and load significantly, and offers little benefit in return.
In general, data compression and decompression slows down all save and some load operations to some extent. In most cases, however, the resulting reduction in file size is worth the additional time spent compressing or decompressing. Because loading is typically done more frequently than saving, load is considered to be the more critical of the two operations. Up to a certain threshold (relative to the size of the uncompressed MAT-file), loading a compressed MAT-File is slightly slower than loading an uncompressed file containing the same data. Beyond that threshold, however, loading the compressed file is faster.
For example, say that you have a block of data that takes up 100 MB in memory, and this data has been saved to both a 10 MB compressed file and a 100 MB uncompressed file. When you load each of these files back into the MATLAB workspace, the first 10 MB of data takes the same amount of time to load for each file. Loading the remaining 90 MB from the uncompressed file will take 9 times as long as the first 10 MB, while all that remains to be done with the compressed file is to decompress the data, and this takes a relatively short amount of time.
The loading size threshold is lower for network files, and also varies depending on the type of computer being used. Network users loading compressed MAT-files gemerally see faster load times than when loading uncompressed files, and at smaller data sizes than users loading the same files locally.
2. Given the wide range of possible combinations of variable sizes, data types, and the number of variables that may be saved to an MAT-file, we don't have statistics on MAT-file performance. To determine whether compression has an affect on your code's performance, you can run the actual application under MATLAB 7.0 (R14) with compression turned on, and turned off.
3. In MATLAB Versions 7.0 through 7.2, you could use the switches –compress, –nocompress, –unicode, and –nounicode with the save function to enable or disable compression and Unicode character encoding in the MAT-file being generated. In MATLAB Version 7.3, the save function no longer supports these switches. Instead, save now creates a MAT-file with compression and Unicode character encoding by default, or with the following command:
save -v7 filename
You can still save to a MAT-file without using compression or Unicode encoding. In fact, you will have to do this in order to create MAT-files that you can load into a MATLAB Version 6 or earlier. To save to a MAT-file without compression or Unicode encoding, type
save -v6 filename
To disable compression and Unicode encoding for all save operations in a MATLAB session, open the MATLAB Preferences dialog, select General and then MAT-Files, and then click the button labelled Ensure backward compatibility (-v6).

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!