Why is it so slow to decompress System. IO. Compression. GZipStream?

Source: Internet
Author: User

Writing the following code makes me very laborious.
. Net provides the Compression example of System. IO. Compression. GZipStream, but there is no good code for decompression.
However, after extracting a section and compressing it, it becomes 1.16 MB, while the original data is 15 MB,
It took up to 3000 milliseconds!

I don't know why. Please kindly advise me!

First paste the Code:

 1    1. public object DeCompression(byte[] request)  
2 2. {
3 3. object ob = new object();
4 4. Stream sourceStream = new MemoryStream(request);
5 5. System.IO.Compression.GZipStream zipStream = new System.IO.Compression.GZipStream(
6 6. sourceStream,
7 7. System.IO.Compression.CompressionMode.Decompress);
8 8. byte[] buffer = new byte[20480];
9 9. byte[] bt = new byte[0];
10 10. int iread = 0;
11 11. do
12 12. {
13 13. iread = zipStream.Read(buffer, 0, 20480);
14 14. byte[] bswap = new byte[bt.Length + buffer.Length];
15 15. Buffer.BlockCopy(bt, 0, bswap, 0, bt.Length);
16 16. Buffer.BlockCopy(buffer, 0, bswap, bt.Length, buffer.Length);
17 17. bt = bswap;
18 18. bswap = null;
19 19. GC.Collect();
20 20. } while (iread > 0);
21 21. zipStream.Close();
22 22. sourceStream.Close();
23 23. MemoryStream ms = new MemoryStream(bt);
24 24. ob = DeSerializeBinary(ms);
25 25. ms.Close();
26 26. return ob;
27 27. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.