-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathZipOutputStream.cs
More file actions
62 lines (53 loc) · 1.45 KB
/
ZipOutputStream.cs
File metadata and controls
62 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.IO;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
namespace ICSharpCode.SharpZipLib.Benchmark.Zip
{
[MemoryDiagnoser]
[Config(typeof(MultipleRuntimes))]
public class ZipOutputStream
{
private const int ChunkCount = 64;
private const int ChunkSize = 1024 * 1024;
private const int N = ChunkCount * ChunkSize;
byte[] outputBuffer;
byte[] inputBuffer;
[GlobalSetup]
public void GlobalSetup()
{
inputBuffer = new byte[ChunkSize];
outputBuffer = new byte[N];
}
[Benchmark]
public long WriteZipOutputStream()
{
using (var memoryStream = new MemoryStream(outputBuffer))
{
using var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream);
zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
for (int i = 0; i < ChunkCount; i++)
{
zipOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
}
return memoryStream.Position;
}
}
[Benchmark]
public async Task<long> WriteZipOutputStreamAsync()
{
using (var memoryStream = new MemoryStream(outputBuffer))
{
using (var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream))
{
zipOutputStream.IsStreamOwner = false;
zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
for (int i = 0; i < ChunkCount; i++)
{
await zipOutputStream.WriteAsync(inputBuffer, 0, inputBuffer.Length);
}
}
return memoryStream.Position;
}
}
}
}