Skip to content

Commit

Permalink
Merge pull request #1144 from JohannesDeml/benchmark-cleanup
Browse files Browse the repository at this point in the history
Benchmark cleanup
  • Loading branch information
AArnott committed Dec 5, 2020
2 parents 15b2ab6 + 66f1d7f commit 0bd93df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 82 deletions.
92 changes: 19 additions & 73 deletions benchmark/SerializerBenchmark/BenchmarkConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public BenchmarkConfig()
Job baseConfig = Job.ShortRun.WithIterationCount(1).WithWarmupCount(1);

// Add(baseConfig.With(Runtime.Clr).With(Jit.RyuJit).With(Platform.X64));
this.Add(baseConfig.With(CoreRuntime.Core31).With(Jit.RyuJit).With(Platform.X64));
this.AddJob(baseConfig.WithRuntime(CoreRuntime.Core31).WithJit(Jit.RyuJit).WithPlatform(Platform.X64));

this.Add(MarkdownExporter.GitHub);
this.Add(CsvExporter.Default);
this.Add(MemoryDiagnoser.Default);
this.AddExporter(MarkdownExporter.GitHub);
this.AddExporter(CsvExporter.Default);
this.AddDiagnoser(MemoryDiagnoser.Default);

this.Add(new DataSizeColumn());
this.AddColumn(new DataSizeColumn());

this.Orderer = new CustomOrderer();
}
Expand Down Expand Up @@ -96,19 +96,24 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style)
{
System.Reflection.MethodInfo mi = benchmarkCase.Descriptor.WorkloadMethod;
if (mi.Name.Contains("Serialize"))
if (!mi.Name.Contains("Serialize"))
{
var instance = Activator.CreateInstance(mi.DeclaringType);
mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value);
mi.DeclaringType.GetMethod("Setup").Invoke(instance, null);

var bytes = (byte[])mi.Invoke(instance, null);
return ToHumanReadableSize(bytes.Length);
return "-";
}
else

var instance = Activator.CreateInstance(mi.DeclaringType);
mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value);
mi.DeclaringType.GetMethod("Setup").Invoke(instance, null);

var bytes = (byte[])mi.Invoke(instance, null);
var byteSize = bytes.Length;
var cultureInfo = summary.GetCultureInfo();
if (style.PrintUnitsInContent)
{
return "-";
return SizeValue.FromBytes(byteSize).ToString(style.SizeUnit, cultureInfo);
}

return byteSize.ToString("0.##", cultureInfo);
}

public bool IsAvailable(Summary summary)
Expand All @@ -120,65 +125,6 @@ public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase)
{
return false;
}

private static string ToHumanReadableSize(long size)
{
return ToHumanReadableSize(new long?(size));
}

private static string ToHumanReadableSize(long? size)
{
if (size == null)
{
return "NULL";
}

double bytes = size.Value;

if (bytes <= 1024)
{
return bytes.ToString("f2") + " B";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " KB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " MB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " GB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " TB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " PB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " EB";
}

bytes = bytes / 1024;
return bytes + " ZB";
}
}
}
}
6 changes: 2 additions & 4 deletions benchmark/SerializerBenchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Benchmark;
using Benchmark.Models;
using BenchmarkDotNet.Running;

namespace ConsoleApp1
namespace Benchmark
{
internal class Program
internal static class Program
{
private static void Main(string[] args)
{
Expand Down
8 changes: 4 additions & 4 deletions benchmark/SerializerBenchmark/SerializerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AllSerializerBenchmark_BytesInOut
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand Down Expand Up @@ -568,7 +568,7 @@ public class MsgPackV1_Vs_MsgPackV2_BytesInOut // : AllSerializerBenchmark
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand Down Expand Up @@ -1099,7 +1099,7 @@ public class ShortRun_AllSerializerBenchmark_BytesInOut

private bool isContractless;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand Down Expand Up @@ -1197,7 +1197,7 @@ public class ShortRun_MsgPackV1_Vs_MsgPackV2_BytesInOut
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand Down
2 changes: 1 addition & 1 deletion benchmark/SerializerBenchmark/SerializerBenchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Ceras" Version="4.1.7" />
<PackageReference Include="FsPickler" Version="5.2.2" />
<PackageReference Include="Hyperion" Version="0.9.11" />
Expand Down

0 comments on commit 0bd93df

Please sign in to comment.