-
Notifications
You must be signed in to change notification settings - Fork 279
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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))] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How long does it take to run this benchmark? We usually avoid Does |
||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was that supposed to be a benchmark too?
Suggested change
|
||||||||||
{ | ||||||||||
ZipFile.ExtractToDirectory(_testInputZipFile, _testOutputDirectory); | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
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 toTestData
, the time reported by the benchmark is going to report a regression.So please keep the zip file. 👍