Skip to content

Instantly share code, notes, and snippets.

@danield137
Created January 20, 2023 01:16
Show Gist options
  • Save danield137/2d9fd3aa7627dbbdbf66390673629615 to your computer and use it in GitHub Desktop.
Save danield137/2d9fd3aa7627dbbdbf66390673629615 to your computer and use it in GitHub Desktop.
Compression Benchmark
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3" />
</ItemGroup>
</Project>
// See https://aka.ms/new-console-template for more information
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
namespace Gzip
{
public static class Program
{
public static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<GzipTest>();
}
}
[Config(typeof(CustomConfiguration))]
public class GzipTest
{
private class CustomConfiguration : ManualConfig
{
public CustomConfiguration()
{
AddJob(Job.Default.WithRuntime(ClrRuntime.Net48));
AddJob(Job.Default.WithRuntime(CoreRuntime.Core50));
AddJob(Job.Default.WithRuntime(CoreRuntime.Core60));
}
}
private byte[] m_b;
[GlobalSetup]
public void Setup()
{
m_b = Encoding.UTF8.GetBytes("[" + string.Join(",", Enumerable.Range(0, 100).Select(i => "{'a':1, 'b': 2, 'c': 'aaa', 'd': " + i + "}")) + "]");
}
[Benchmark]
public int Baseline()
{
using (var target = new MemoryStream())
{
using (var gzip = new GZipStream(target, CompressionLevel.Fastest))
{
gzip.Write(m_b, 0, m_b.Length);
return target.ToArray().Length;
}
}
}
}
}
@danield137
Copy link
Author

BenchmarkDotNet=v0.13.3, OS=Windows 11 (10.0.22623.1095)
Intel Core i9-10885H CPU 2.40GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.102
[Host] : .NET 6.0.13 (6.0.1322.58009), X64 RyuJIT AVX2
Job-ZPGVIO : .NET 5.0.17 (5.0.1722.21314), X64 RyuJIT AVX2
Job-SWIFMF : .NET 6.0.13 (6.0.1322.58009), X64 RyuJIT AVX2
Job-XEFOHW : .NET Framework 4.8.1 (4.8.9105.0), X64 RyuJIT VectorSize=256

Method Runtime Mean Error StdDev
Baseline .NET 5.0 13.21 us 0.655 us 1.836 us
Baseline .NET 6.0 14.13 us 0.661 us 1.865 us
Baseline .NET Framework 4.8 37.25 us 0.392 us 0.306 us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment