为何我用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 . }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值