mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-11-15 17:02:03 +00:00
Merge remote-tracking branch 'origin/master' into perf/7zip-profile-pooling
# Conflicts: # src/SharpCompress/Compressors/LZMA/Lzma2EncoderStream.cs # src/SharpCompress/Compressors/LZMA/LzmaStream.Async.cs # src/SharpCompress/IO/ReadOnlyMemoryStream.cs
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress.Performance.Benchmarks;
|
||||
|
||||
@@ -45,6 +46,22 @@ public class GZipBenchmarks
|
||||
await gzipStream.WriteAsync(_sourceData, 0, _sourceData.Length).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Benchmark(Description = "GZip: Compress 100KB (Pooled)")]
|
||||
public void GZipCompressPooled()
|
||||
{
|
||||
using var outputStream = new PooledMemoryStream();
|
||||
using var gzipStream = new GZipStream(outputStream, CompressionMode.Compress);
|
||||
gzipStream.Write(_sourceData, 0, _sourceData.Length);
|
||||
}
|
||||
|
||||
[Benchmark(Description = "GZip: Compress 100KB (Async, Pooled)")]
|
||||
public async Task GZipCompressAsyncPooled()
|
||||
{
|
||||
using var outputStream = new PooledMemoryStream();
|
||||
using var gzipStream = new GZipStream(outputStream, CompressionMode.Compress);
|
||||
await gzipStream.WriteAsync(_sourceData, 0, _sourceData.Length).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Benchmark(Description = "GZip: Decompress 100KB")]
|
||||
public void GZipDecompress()
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Tar;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.IO;
|
||||
using SharpCompress.Providers;
|
||||
using SharpCompress.Providers.System;
|
||||
using SharpCompress.Readers;
|
||||
@@ -127,6 +128,38 @@ public class TarBenchmarks : ArchiveBenchmarkBase
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Tar: Create archive with small files (Pooled)")]
|
||||
public void TarCreateSmallFilesPooled()
|
||||
{
|
||||
using var outputStream = new PooledMemoryStream();
|
||||
using var writer = WriterFactory.OpenWriter(
|
||||
outputStream,
|
||||
ArchiveType.Tar,
|
||||
new WriterOptions(CompressionType.None) { LeaveStreamOpen = true }
|
||||
);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
using var entryStream = new MemoryStream(new byte[1024]);
|
||||
writer.Write($"file{i}.txt", entryStream);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Tar: Create archive with small files (Async, Pooled)")]
|
||||
public async Task TarCreateSmallFilesAsyncPooled()
|
||||
{
|
||||
using var outputStream = new PooledMemoryStream();
|
||||
await using var writer = await WriterFactory.OpenAsyncWriter(
|
||||
outputStream,
|
||||
ArchiveType.Tar,
|
||||
new WriterOptions(CompressionType.None) { LeaveStreamOpen = true }
|
||||
);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
using var entryStream = new MemoryStream(new byte[1024]);
|
||||
await writer.WriteAsync($"file{i}.txt", entryStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Tar: Create archive with small files")]
|
||||
public void TarCreateSmallFiles()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using BenchmarkDotNet.Attributes;
|
||||
using SharpCompress.Archives.Zip;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.IO;
|
||||
using SharpCompress.Providers;
|
||||
using SharpCompress.Providers.System;
|
||||
using SharpCompress.Readers;
|
||||
@@ -114,6 +115,38 @@ public class ZipBenchmarks : ArchiveBenchmarkBase
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Zip: Create archive with small files (Pooled)")]
|
||||
public void ZipCreateSmallFilesPooled()
|
||||
{
|
||||
using var outputStream = new PooledMemoryStream();
|
||||
using var writer = WriterFactory.OpenWriter(
|
||||
outputStream,
|
||||
ArchiveType.Zip,
|
||||
new WriterOptions(CompressionType.Deflate) { LeaveStreamOpen = true }
|
||||
);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
using var entryStream = new MemoryStream(new byte[1024]);
|
||||
writer.Write($"file{i}.txt", entryStream);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Zip: Create archive with small files (Async, Pooled)")]
|
||||
public async Task ZipCreateSmallFilesAsyncPooled()
|
||||
{
|
||||
using var outputStream = new PooledMemoryStream();
|
||||
await using var writer = await WriterFactory.OpenAsyncWriter(
|
||||
outputStream,
|
||||
ArchiveType.Zip,
|
||||
new WriterOptions(CompressionType.Deflate) { LeaveStreamOpen = true }
|
||||
);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
using var entryStream = new MemoryStream(new byte[1024]);
|
||||
await writer.WriteAsync($"file{i}.txt", entryStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Description = "Zip: Create archive with small files")]
|
||||
public void ZipCreateSmallFiles()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user