Decompressing zip files with C#

August 22, 2008

Which is the fastest way to decompress ZIP files (fragments actually) using C#?

I tried with SharpZipLib vs zlib.net vs a wrapper on top of zlib 1.2.3.

Which one is faster?

I tried with the same test file, repeating 1000 times and these are the results:


$ time mono unzip.exe file ziplib 1000

real 0m4.491s
user 0m4.392s
sys 0m0.119s

$ time mono unzip.exe file sharp 1000

real 0m3.631s
user 0m3.550s
sys 0m0.090s

$ time mono unzip.exe file zlib 1000

real 0m1.754s
user 0m1.684s
sys 0m0.079s


Clear, right?

So, the zlib wrapper is two times faster than SharpZipLib which, in turn, is faster than zlib.net

For zlib wrapper I just called the uncompress method.

With SharpZipLib I used InflaterInputStream

InflaterInputStream st = new InflaterInputStream(file, new Inflater(true));

and for zlib.NET

zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outStream);

Hope it helps!

7 comments :

Georg Wächter said...

how big what the file?

pablo said...

Hi,

I tried with both small files (28Kb) and then a big number of text and binary files (about 3000), and zlib seems to be always faster

Anonymous said...

Sounds normal.

Where can one get your zlib binding?

Alexandre Gomes said...

Hi,

You should try the 7zip C# lib too. I'm not sure if its faster, or not, but I'm sure I've been pretty satisfied with its results compressing a Webservice requests and responses in real-time to some huge resultsets (up to 10MB of data each).

Cheers,

pablo said...

Hi,

If you can use a GPL library, you can take a look at:

http://www.koders.com/csharp/fid91385D2988B36B949C4771DF3BCD36519D43154A.aspx

pablo said...

Hi Alexandre,

Thanks! I'll try to find the 7zip lib!

Alexandre Gomes said...

Sorry about that, forgot the link :P

http://www.7-zip.org/sdk.html

Real Time Web Analytics