As far as I understand, the Binary Data feature of Mathematica can efficiently store raw numbers or elements of a given type to binary files. Is there a way to store a large symbolic expression (read - wild mixture of all possible element types) in a binary format that can be quickly saved and loaded back into memory?
1 Answer
Look at BinarySerialize
, particularly the option PerformanceGoal -> "Size"
. It's even better than Compress
data = {
RandomReal[1, {10, 10000}],
ExampleData[{"TestImage", "House"}],
ExampleData[{"Dataset", "Planets"}],
ExampleData[{"Text", "UNHumanRightsEnglish"}]
};
ByteCount /@ Through[{BinarySerialize, Compress}[data]]
(* {1027513, 1220720} *)
DumpSave["test1.mx", data];
dataz = BinarySerialize[data, PerformanceGoal -> "Size"];
DumpSave["test2.mx", dataz];
FileSize /@ {"test1.mx", "test2.mx"}
(* {Quantity[1.0258, "Megabytes"], Quantity[0.915118, "Megabytes"]} *)
DumpSave
? $\endgroup$BinarySerialize
uses theWXF
format. $\endgroup$DumpSave
or export toMX
format seems to be by far the best bet... $\endgroup$