为何我用System.IO.Compression.GZipStream解压缩,速度这么慢?

写出如下的代码,让我很是费力。
.net 提供了System.IO.Compression.GZipStream的压缩示例,却没有很好的解压缩的代码。
无奈自己实现了一段,但是在解压一段压缩后成为1.16MB,而原始数据为15MB的数据时,
竟耗时达3000毫秒左右!

不知原因为何,请高手不禀赐教!

先贴一下代码:

  
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 . }

你可能感兴趣的:(compression)