Skip to content

Commit 1a12d9c

Browse files
Numpsypiksel
authored andcommitted
Merge PR #330: Add a benchmarks project using BenchmarkDotNet
1 parent 98bbdda commit 1a12d9c

File tree

8 files changed

+285
-3
lines changed

8 files changed

+285
-3
lines changed

ICSharpCode.SharpZipLib.sln

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.9
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28705.295
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Configuration", "Solution Configuration", "{F1097E98-4DEB-4A0A-81EE-5CEC667EBDF0}"
77
ProjectSection(SolutionItems) = preProject
@@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib", "
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib.Tests", "test\ICSharpCode.SharpZipLib.Tests\ICSharpCode.SharpZipLib.Tests.csproj", "{82211166-9C45-4603-8E3A-2CA2EFFCBC26}"
1717
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpZipLib.TestBootstrapper", "test\ICSharpCode.SharpZipLib.TestBootstrapper\ICSharpCode.SharpZipLib.TestBootstrapper.csproj", "{535D7365-C5B1-4253-9233-D72D972CA851}"
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib.TestBootstrapper", "test\ICSharpCode.SharpZipLib.TestBootstrapper\ICSharpCode.SharpZipLib.TestBootstrapper.csproj", "{535D7365-C5B1-4253-9233-D72D972CA851}"
19+
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.SharpZipLib.Benchmark", "benchmark\ICSharpCode.SharpZipLib.Benchmark\ICSharpCode.SharpZipLib.Benchmark.csproj", "{C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}"
1921
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -35,8 +37,15 @@ Global
3537
{535D7365-C5B1-4253-9233-D72D972CA851}.Debug|Any CPU.Build.0 = Debug|Any CPU
3638
{535D7365-C5B1-4253-9233-D72D972CA851}.Release|Any CPU.ActiveCfg = Release|Any CPU
3739
{535D7365-C5B1-4253-9233-D72D972CA851}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{C51E638B-DDD0-48B6-A6BD-EBC4E6A104C7}.Release|Any CPU.Build.0 = Release|Any CPU
3844
EndGlobalSection
3945
GlobalSection(SolutionProperties) = preSolution
4046
HideSolutionNode = FALSE
4147
EndGlobalSection
48+
GlobalSection(ExtensibilityGlobals) = postSolution
49+
SolutionGuid = {0A049193-65F8-49AF-82CB-75D42563DA16}
50+
EndGlobalSection
4251
EndGlobal
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace ICSharpCode.SharpZipLib.Benchmark.Checksum
5+
{
6+
[Config(typeof(MultipleRuntimes))]
7+
public class Adler32
8+
{
9+
private const int ChunkCount = 256;
10+
private const int ChunkSize = 1024 * 1024;
11+
private const int N = ChunkCount * ChunkSize;
12+
private readonly byte[] data;
13+
14+
public Adler32()
15+
{
16+
data = new byte[N];
17+
new Random(1).NextBytes(data);
18+
}
19+
20+
[Benchmark]
21+
public long Adler32LargeUpdate()
22+
{
23+
var adler32 = new ICSharpCode.SharpZipLib.Checksum.Adler32();
24+
adler32.Update(data);
25+
return adler32.Value;
26+
}
27+
28+
/*
29+
[Benchmark]
30+
public long Adler32ChunkedUpdate()
31+
{
32+
var adler32 = new ICSharpCode.SharpZipLib.Checksum.Adler32();
33+
34+
for (int i = 0; i < ChunkCount; i++)
35+
{
36+
var segment = new ArraySegment<byte>(data, ChunkSize * i, ChunkSize);
37+
adler32.Update(segment);
38+
}
39+
40+
return adler32.Value;
41+
}
42+
*/
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace ICSharpCode.SharpZipLib.Benchmark.Checksum
5+
{
6+
[Config(typeof(MultipleRuntimes))]
7+
public class BZip2Crc
8+
{
9+
private const int ChunkCount = 256;
10+
private const int ChunkSize = 1024 * 1024;
11+
private const int N = ChunkCount * ChunkSize;
12+
private readonly byte[] data;
13+
14+
public BZip2Crc()
15+
{
16+
data = new byte[N];
17+
new Random(1).NextBytes(data);
18+
}
19+
20+
[Benchmark]
21+
public long BZip2CrcLargeUpdate()
22+
{
23+
var bzipCrc = new ICSharpCode.SharpZipLib.Checksum.BZip2Crc();
24+
bzipCrc.Update(data);
25+
return bzipCrc.Value;
26+
}
27+
28+
/*
29+
[Benchmark]
30+
public long BZip2CrcChunkedUpdate()
31+
{
32+
var bzipCrc = new ICSharpCode.SharpZipLib.Checksum.BZip2Crc();
33+
34+
for (int i = 0; i < ChunkCount; i++)
35+
{
36+
var segment = new ArraySegment<byte>(data, ChunkSize * i, ChunkSize);
37+
bzipCrc.Update(segment);
38+
}
39+
40+
return bzipCrc.Value;
41+
}
42+
*/
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace ICSharpCode.SharpZipLib.Benchmark.Checksum
5+
{
6+
[Config(typeof(MultipleRuntimes))]
7+
public class Crc32
8+
{
9+
private const int ChunkCount = 256;
10+
private const int ChunkSize = 1024 * 1024;
11+
private const int N = ChunkCount * ChunkSize;
12+
private readonly byte[] data;
13+
14+
public Crc32()
15+
{
16+
data = new byte[N];
17+
new Random(1).NextBytes(data);
18+
}
19+
20+
[Benchmark]
21+
public long Crc32LargeUpdate()
22+
{
23+
var crc32 = new ICSharpCode.SharpZipLib.Checksum.Crc32();
24+
crc32.Update(data);
25+
return crc32.Value;
26+
}
27+
28+
/*
29+
[Benchmark]
30+
public long Crc32ChunkedUpdate()
31+
{
32+
var crc32 = new ICSharpCode.SharpZipLib.Checksum.Crc32();
33+
34+
for (int i = 0; i < ChunkCount; i++)
35+
{
36+
var segment = new ArraySegment<byte>(data, ChunkSize * i, ChunkSize);
37+
crc32.Update(segment);
38+
}
39+
40+
return crc32.Value;
41+
}
42+
*/
43+
}
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="BenchmarkDotNet">
10+
<Version>0.11.4</Version>
11+
</PackageReference>
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\ICSharpCode.SharpZipLib\ICSharpCode.SharpZipLib.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using BenchmarkDotNet;
3+
using BenchmarkDotNet.Configs;
4+
using BenchmarkDotNet.Jobs;
5+
using BenchmarkDotNet.Running;
6+
using BenchmarkDotNet.Toolchains.CsProj;
7+
8+
namespace ICSharpCode.SharpZipLib.Benchmark
9+
{
10+
public class MultipleRuntimes : ManualConfig
11+
{
12+
public MultipleRuntimes()
13+
{
14+
Add(Job.Default.With(CsProjClassicNetToolchain.Net461).AsBaseline()); // NET 4.6.1
15+
Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp21)); // .NET Core 2.1
16+
//Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp30)); // .NET Core 3.0
17+
}
18+
}
19+
20+
class Program
21+
{
22+
static void Main(string[] args)
23+
{
24+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
25+
}
26+
}
27+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.IO;
3+
using BenchmarkDotNet.Attributes;
4+
5+
namespace ICSharpCode.SharpZipLib.Benchmark.Zip
6+
{
7+
[Config(typeof(MultipleRuntimes))]
8+
public class ZipInputStream
9+
{
10+
private const int ChunkCount = 64;
11+
private const int ChunkSize = 1024 * 1024;
12+
private const int N = ChunkCount * ChunkSize;
13+
14+
byte[] zippedData;
15+
16+
public ZipInputStream()
17+
{
18+
using (var memoryStream = new MemoryStream())
19+
{
20+
using (var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream))
21+
{
22+
zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
23+
24+
var inputBuffer = new byte[ChunkSize];
25+
26+
for (int i = 0; i < ChunkCount; i++)
27+
{
28+
zipOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
29+
}
30+
}
31+
32+
zippedData = memoryStream.ToArray();
33+
}
34+
}
35+
36+
[Benchmark]
37+
public long ReadZipInputStream()
38+
{
39+
using (var memoryStream = new MemoryStream(zippedData))
40+
{
41+
using (var zipInputStream = new SharpZipLib.Zip.ZipInputStream(memoryStream))
42+
{
43+
var buffer = new byte[4096];
44+
var entry = zipInputStream.GetNextEntry();
45+
46+
while (zipInputStream.Read(buffer, 0, buffer.Length) > 0)
47+
{
48+
49+
}
50+
51+
return entry.Size;
52+
}
53+
}
54+
}
55+
}
56+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.IO;
3+
using BenchmarkDotNet.Attributes;
4+
5+
namespace ICSharpCode.SharpZipLib.Benchmark.Zip
6+
{
7+
[Config(typeof(MultipleRuntimes))]
8+
public class ZipOutputStream
9+
{
10+
private const int ChunkCount = 64;
11+
private const int ChunkSize = 1024 * 1024;
12+
private const int N = ChunkCount * ChunkSize;
13+
14+
byte[] outputBuffer;
15+
byte[] inputBuffer;
16+
17+
public ZipOutputStream()
18+
{
19+
inputBuffer = new byte[ChunkSize];
20+
outputBuffer = new byte[N];
21+
}
22+
23+
[Benchmark]
24+
public long WriteZipOutputStream()
25+
{
26+
using (var memoryStream = new MemoryStream(outputBuffer))
27+
{
28+
var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream);
29+
zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
30+
31+
for (int i = 0; i < ChunkCount; i++)
32+
{
33+
zipOutputStream.Write(inputBuffer, 0, inputBuffer.Length);
34+
}
35+
36+
return memoryStream.Position;
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)