File compression is organized as follows:

using (Stream fs = File.OpenRead(fileInput)) using (Stream fd = File.Create(FileOut)) using (Stream csStream = new GZipStream(fd, CompressionMode.Compress)) { byte[] buffer = new byte[1024]; int nRead; try { while ((nRead = fs.Read(buffer, 0, buffer.Length)) > 0) { csStream.Write(buffer, 0, nRead); } } 

Although it is written in msdn that GZip itself is able to distribute threads most efficiently, but in fact it turns out that the CPU load is only 25%. How can you modify this piece of code to use as much system resources as possible to speed up the compression process?

  • And why not try this: pastebin.com/uEdgqqEu ? - VladD
  • Cannot be implemented on 3.5 I will add to the question so that there are no such comments anymore) - Garrus_En
  • Well, increase the buffer size at least. How do you think it is possible to effectively parallelize the packaging of the unfortunate one kilobyte of data? - VladD
  • It turns out that changing this parameter doesn’t change anything) when launched, VS shows that all processes are loaded by 25% strictly, it’s as if the load on other processors is not distributed at all - Garrus_En
  • Perhaps, in the old version of GZip, tai did not know how to distribute the streams as they should. Try to check in the new version. - VladD

0