Think about Loose Coupling | |
PerlMonks |
Re: Spreadsheet::WriteExcel large files (text versus binary format)by BrowserUk (Patriarch) |
on Jan 02, 2012 at 10:55 UTC ( [id://945887]=note: print w/replies, xml ) | Need Help?? |
I am using Spreadsheet::WriteExcel to create a file with 20,000 lines. The size of the file is quite large - over 100 megabytes. The difference is simply that between the text formatting of your input file and the binary data format of .xls files. Your input is ascii-encoded tab separated values. 1 million records each of 100 small integers takes nearly 400MB:
Conversely, that same data stored as binary takes just 2MB:
Mind you, compared with the latest file format used for such data, that ridiculous 200:1 size ratio is positively sane. The same data stored as XML:
Takes up an absolutely ludicrous 2.2 Gigabytes or over 1000 times as much space to hold the exact same data! Of course, the anti-binary file lobby and XML advocates will tell you that "binary files can't be manually inspected and edited" the way text files can. But really? Who is going to manually verify or edit 2 million numbers? Let alone do so whilst wading their way through the 2.2GB of pointless, repetitive, eye-crossing verbosity that is XML. And then there is that other stand-by defence: "Disk space is cheap". Which is true. But IO transfer time and encoding/decoding costs definitely aren't. They'll also say that text formats compress with much higher compression ratios than binary data, which they do. But that completely misses the point that even compressed with the very best algorithms, these text formats still require 100s of times more space than the uncompressed binary data. The text version:
And the XML version:
Sure, a 10:1 compression rate is amazing, until you realise that the result still takes up 100 times as much space as the raw binary data. And it will therefore take 100 times as long to read from disk. Not to mention the 7 minutes of CPU it took to compress it; and the 2 minutes of CPU it'll take to decompress it and another 2 minutes of CPU it'll take to parse the XML; in order to get back the 2MB of data it contains that can be loaded from disk in less than 1 second. So the answer to your question: "how I can make the original file smaller?" is, store it in binary format and save time, hassle, disk and cpu. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|