zlib performance

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 7 00:41:17 PDT 2015


On Fri, 07 Aug 2015 07:19:43 +0000
"yawniek" <dlang at srtnwz.com> wrote:

> hi,
> 
> unpacking files is kinda slow, probably i'm doing something wrong.
> 
> below code is about half the speed of gnu zcat on my os x machine.
> why?
> 
> why do i need to .dup the buffer?

It depends. In your case you don't need to.

byChunk() reuse buffer which means, after each call same buffer is use,
so all previous data are gone.


> can i get rid of the casts?
> 

Yes, you can use std.conv.to

import 
  std.zlib, 
  std.file,
  std.stdio,
  std.conv;

void main(string[] args)
{
  auto f = File(args[1], "rb");
  auto uncompressor = new UnCompress(HeaderFormat.gzip);

  foreach (buffer; f.byChunk(4096))
  {
          auto uncompressed = to!(char[])(uncompressor.uncompress(buffer));
          write(uncompressed);
  }
}





More information about the Digitalmars-d-learn mailing list