Created
January 20, 2023 01:16
-
-
Save danield137/2d9fd3aa7627dbbdbf66390673629615 to your computer and use it in GitHub Desktop.
Compression Benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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