Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve block benchmarks #63

Merged
merged 1 commit into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Snappier.Benchmarks/BlockCompressHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public void LoadToMemory()
using var resource =
typeof(BlockCompressHtml).Assembly.GetManifestResourceStream("Snappier.Benchmarks.TestData.html");

byte[] input = new byte[65536]; // Just test the first 64KB
byte[] input = new byte[resource!.Length];
int inputLength = resource!.Read(input, 0, input.Length);
_input = input.AsMemory(0, inputLength);

_output = new byte[65536];
_output = new byte[Snappy.GetMaxCompressedLength(inputLength)];
}

[Benchmark]
Expand Down
12 changes: 8 additions & 4 deletions Snappier.Benchmarks/BlockDecompressHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ namespace Snappier.Benchmarks
public class BlockDecompressHtml
{
private ReadOnlyMemory<byte> _input;
private Memory<byte> _output;

[GlobalSetup]
public void LoadToMemory()
{
using var resource =
typeof(DecompressHtml).Assembly.GetManifestResourceStream("Snappier.Benchmarks.TestData.html");

var input = new byte[65536]; // Just test the first 64KB
byte[] input = new byte[65536]; // Just test the first 64KB
// ReSharper disable once PossibleNullReferenceException
resource.Read(input, 0, input.Length);
int inputLength = resource!.Read(input, 0, input.Length);

var compressed = new byte[Snappy.GetMaxCompressedLength(input.Length)];
var compressedLength = Snappy.Compress(input, compressed);
byte[] compressed = new byte[Snappy.GetMaxCompressedLength(inputLength)];
int compressedLength = Snappy.Compress(input.AsSpan(0, inputLength), compressed);

_input = compressed.AsMemory(0, compressedLength);

_output = new byte[65536];
}


Expand All @@ -31,6 +34,7 @@ public void Decompress()
var decompressor = new SnappyDecompressor();

decompressor.Decompress(_input.Span);
decompressor.Read(_output.Span);
}
}
}
7 changes: 3 additions & 4 deletions Snappier.Benchmarks/Configuration/VersionComparisonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ private class VersionComparisonOrderer : IOrderer
public IEnumerable<BenchmarkCase> GetExecutionOrder(ImmutableArray<BenchmarkCase> benchmarksCase,
IEnumerable<BenchmarkLogicalGroupRule> order = null) =>
benchmarksCase
.OrderBy(p => p.Job.Environment.Runtime.Name)
.ThenBy(p => p.Job.Environment.EnvironmentVariables?.FirstOrDefault(
q => q.Key == PgoColumn.PgoEnvironmentVariableName)?.Value ?? "0")
.OrderBy(p => p.Job.Environment.Runtime.MsBuildMoniker)
.ThenBy(p => PgoColumn.IsPgo(p) ? 1 : 0)
.ThenBy(p => p.DisplayInfo)
.ThenBy(p => !p.Descriptor.Baseline);

Expand All @@ -65,7 +64,7 @@ public IEnumerable<BenchmarkCase> GetSummaryOrder(ImmutableArray<BenchmarkCase>

public string GetLogicalGroupKey(ImmutableArray<BenchmarkCase> allBenchmarksCases,
BenchmarkCase benchmarkCase) =>
$"{benchmarkCase.Job.Environment.Runtime.Name}-Pgo={(PgoColumn.IsPgo(benchmarkCase) ? "Y" : "N")}";
$"{benchmarkCase.Job.Environment.Runtime.MsBuildMoniker}-Pgo={(PgoColumn.IsPgo(benchmarkCase) ? "Y" : "N")}";

public IEnumerable<IGrouping<string, BenchmarkCase>> GetLogicalGroupOrder(
IEnumerable<IGrouping<string, BenchmarkCase>> logicalGroups,
Expand Down