From 8e4d14428f382d19cb2adcad524eb885f5ff864d Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Thu, 13 May 2021 17:52:20 +0100 Subject: [PATCH] PR #634: add an async version of the WriteZipOutputStream benchmark --- .gitignore | 1 + .../Zip/ZipOutputStream.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.gitignore b/.gitignore index 7bc034335..e5f2a21e1 100644 --- a/.gitignore +++ b/.gitignore @@ -253,3 +253,4 @@ paket-files/ /test/ICSharpCode.SharpZipLib.TestBootstrapper/Properties/launchSettings.json _testRunner/ docs/help/api/.manifest +/benchmark/ICSharpCode.SharpZipLib.Benchmark/BenchmarkDotNet.Artifacts/results diff --git a/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs b/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs index 0727ea6f2..ed125c1c7 100644 --- a/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs +++ b/benchmark/ICSharpCode.SharpZipLib.Benchmark/Zip/ZipOutputStream.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; namespace ICSharpCode.SharpZipLib.Benchmark.Zip @@ -37,5 +38,25 @@ public long WriteZipOutputStream() return memoryStream.Position; } } + + [Benchmark] + public async Task 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; + } + } } }