Skip to content

Commit 23538cd

Browse files
committed
Update test suite
1 parent db457d2 commit 23538cd

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net6.0;netcoreapp3.1;net462</TargetFrameworks>
6-
</PropertyGroup>
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net462;net6.0</TargetFrameworks>
6+
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="BenchmarkDotNet">
10-
<Version>0.12.1</Version>
11-
</PackageReference>
9+
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
1210
</ItemGroup>
1311

1412
<ItemGroup>
15-
<ProjectReference Include="..\..\src\ICSharpCode.SharpZipLib\ICSharpCode.SharpZipLib.csproj" />
13+
<ProjectReference Include="..\..\src\ICSharpCode.SharpZipLib\ICSharpCode.SharpZipLib.csproj" />
1614
</ItemGroup>
1715

1816
</Project>

benchmark/ICSharpCode.SharpZipLib.Benchmark/Program.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ public class MultipleRuntimes : ManualConfig
99
{
1010
public MultipleRuntimes()
1111
{
12-
AddJob(Job.Default.WithToolchain(CsProjClassicNetToolchain.Net461).AsBaseline()); // NET 4.6.1
13-
AddJob(Job.Default.WithToolchain(CsProjCoreToolchain.NetCoreApp21)); // .NET Core 2.1
14-
AddJob(Job.Default.WithToolchain(CsProjCoreToolchain.NetCoreApp31)); // .NET Core 3.1
12+
AddJob(Job.Default.WithToolchain(CsProjClassicNetToolchain.Net462).AsBaseline()); // NET 4.6.2
13+
AddJob(Job.Default.WithToolchain(CsProjCoreToolchain.NetCoreApp60)); // .NET 6.0
1514
}
1615
}
1716

benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipInputStream.cs

+47-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.IO;
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
35
using BenchmarkDotNet.Attributes;
6+
using ICSharpCode.SharpZipLib.Zip;
47

58
namespace ICSharpCode.SharpZipLib.Benchmark.Zip
69
{
@@ -14,14 +17,16 @@ public class ZipInputStream
1417

1518
byte[] zippedData;
1619
byte[] readBuffer = new byte[4096];
20+
private string zipFileWithLargeAmountOfEntriesPath;
1721

18-
public ZipInputStream()
22+
[GlobalSetup]
23+
public async Task GlobalSetup()
1924
{
2025
using (var memoryStream = new MemoryStream())
2126
{
2227
using (var zipOutputStream = new SharpZipLib.Zip.ZipOutputStream(memoryStream))
2328
{
24-
zipOutputStream.PutNextEntry(new SharpZipLib.Zip.ZipEntry("0"));
29+
zipOutputStream.PutNextEntry(new ZipEntry("0"));
2530

2631
var inputBuffer = new byte[ChunkSize];
2732

@@ -33,6 +38,29 @@ public ZipInputStream()
3338

3439
zippedData = memoryStream.ToArray();
3540
}
41+
42+
// large real-world test file from test262 repository
43+
string commitSha = "2e4e0e6b8ebe3348a207144204cb6d7a5571c863";
44+
zipFileWithLargeAmountOfEntriesPath = Path.Combine(Path.GetTempPath(), $"{commitSha}.zip");
45+
if (!File.Exists(zipFileWithLargeAmountOfEntriesPath))
46+
{
47+
var uri = $"https://github.com/tc39/test262/archive/{commitSha}.zip";
48+
49+
Console.WriteLine("Loading test262 repository archive from {0}", uri);
50+
51+
using (var client = new HttpClient())
52+
{
53+
using (var downloadStream = await client.GetStreamAsync(uri))
54+
{
55+
using (var writeStream = File.OpenWrite(zipFileWithLargeAmountOfEntriesPath))
56+
{
57+
await downloadStream.CopyToAsync(writeStream);
58+
Console.WriteLine("File downloaded and saved to {0}", zipFileWithLargeAmountOfEntriesPath);
59+
}
60+
}
61+
}
62+
}
63+
3664
}
3765

3866
[Benchmark]
@@ -46,12 +74,28 @@ public long ReadZipInputStream()
4674

4775
while (zipInputStream.Read(readBuffer, 0, readBuffer.Length) > 0)
4876
{
49-
5077
}
5178

5279
return entry.Size;
5380
}
5481
}
5582
}
83+
84+
[Benchmark]
85+
public void ReadLargeZipFile()
86+
{
87+
using (var file = new ZipFile(zipFileWithLargeAmountOfEntriesPath))
88+
{
89+
foreach (ZipEntry entry in file)
90+
{
91+
using (var stream = file.GetInputStream(entry))
92+
{
93+
while (stream.Read(readBuffer, 0, readBuffer.Length) > 0)
94+
{
95+
}
96+
}
97+
}
98+
}
99+
}
56100
}
57101
}

0 commit comments

Comments
 (0)