Skip to content

Add benchmarks for ZipFile.CreateFromDirectory and ZipFile.ExtractToDirectory #4764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/benchmarks/micro/MicroBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<None Update="libraries\System.IO.Compression\TestData\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="libraries\System.IO.Compression\TestZipFile.zip">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about suggesting to just zip TestData during [GlobalSetup] but then I've realized that if somebody adds new file to TestData, the time reported by the benchmark is going to report a regression.

So please keep the zip file. 👍

<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="libraries\System.Text.RegularExpressions\TestData\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using BenchmarkDotNet.Attributes;
using MicroBenchmarks;

namespace System.IO.Compression;

[BenchmarkCategory(Categories.Libraries, Categories.NoWASM)]
public class ZipFileTests
{
private static readonly string _testOutputDirectory = FileUtils.GetTestFilePath();
private static readonly string _testOutputZipFile = Path.Combine(_testOutputDirectory, "TestOutputZipFile.zip");
private static readonly string _testInputDirectory = Path.Combine(
AppContext.BaseDirectory, "libraries", "System.IO.Compression", "TestData");
private static readonly string _testInputZipFile = Path.Combine(
AppContext.BaseDirectory, "libraries", "System.IO.Compression", "TestInputZipFile.zip");

[IterationSetup(Target = nameof(ZipFileCreateFromDirectory))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long does it take to run this benchmark? We usually avoid [IterationSetup] for the reasons described here:

https://github.com/dotnet/performance/blob/main/docs/microbenchmark-design-guidelines.md#iterationsetup

Does ZipFile.CreateFromDirectory overwrite the file?

public void IterationSetup()
{
Directory.CreateDirectory(_testOutputDirectory);
}

[IterationCleanup(Target = nameof(ZipFileCreateFromDirectory))]
public void IterationCleanup()
{
Directory.Delete(_testOutputDirectory, recursive: true);
}

[Benchmark]
public void ZipFileCreateFromDirectory()
{
ZipFile.CreateFromDirectory(_testInputDirectory, _testOutputZipFile);
}

public void ZipFileExtractToDirectory()
Comment on lines +37 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that supposed to be a benchmark too?

Suggested change
public void ZipFileExtractToDirectory()
[Benchmark]
public void ZipFileExtractToDirectory()

{
ZipFile.ExtractToDirectory(_testInputZipFile, _testOutputDirectory);
}
}
Loading