Skip to content

Commit

Permalink
there is no need for the warmup workaround anymore, dotnet/BenchmarkD…
Browse files Browse the repository at this point in the history
…otNet#1573 has solved the problem
  • Loading branch information
adamsitnik committed Nov 9, 2020
1 parent 4146963 commit 6c3b2e3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 37 deletions.
22 changes: 7 additions & 15 deletions src/benchmarks/micro/Serializers/Json_FromString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,25 @@ namespace MicroBenchmarks.Serializers
[GenericTypeArguments(typeof(CollectionsOfPrimitives))]
public class Json_FromString<T>
{
private readonly T value;
private string serialized;

public Json_FromString() => value = DataGenerator.Generate<T>();

[GlobalSetup(Target = nameof(Jil_))]
public void SerializeJil()
{
serialized = Jil.JSON.Serialize<T>(value, Jil.Options.ISO8601);

Jil_(); // workaround for https://github.com/dotnet/BenchmarkDotNet/issues/837
}

[GlobalSetup(Target = nameof(JsonNet_))]
public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(value);

[GlobalSetup(Target = nameof(Utf8Json_))]
public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(value);
public void SetupJil() => serialized = Jil.JSON.Serialize<T>(DataGenerator.Generate<T>(), Jil.Options.ISO8601);

[BenchmarkCategory(Categories.ThirdParty)]
[Benchmark(Description = "Jil")]
public T Jil_() => Jil.JSON.Deserialize<T>(serialized, Jil.Options.ISO8601);

[GlobalSetup(Target = nameof(JsonNet_))]
public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DataGenerator.Generate<T>());

[BenchmarkCategory(Categories.Runtime, Categories.Libraries, Categories.ThirdParty)]
[Benchmark(Description = "JSON.NET")]
public T JsonNet_() => Newtonsoft.Json.JsonConvert.DeserializeObject<T>(serialized);

[GlobalSetup(Target = nameof(Utf8Json_))]
public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(DataGenerator.Generate<T>());

[BenchmarkCategory(Categories.ThirdParty)]
[Benchmark(Description = "Utf8Json")]
public T Utf8Json_() => Utf8Json.JsonSerializer.Deserialize<T>(serialized);
Expand Down
12 changes: 5 additions & 7 deletions src/benchmarks/micro/Serializers/Json_ToStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ namespace MicroBenchmarks.Serializers
[GenericTypeArguments(typeof(CollectionsOfPrimitives))]
public class Json_ToStream<T>
{
private readonly T value;
private T value;

private readonly MemoryStream memoryStream;
private readonly StreamWriter streamWriter;
private MemoryStream memoryStream;
private StreamWriter streamWriter;

private DataContractJsonSerializer dataContractJsonSerializer;
private Newtonsoft.Json.JsonSerializer newtonSoftJsonSerializer;

public Json_ToStream()
[GlobalSetup]
public void Setup()
{
value = DataGenerator.Generate<T>();

Expand All @@ -36,9 +37,6 @@ public Json_ToStream()
newtonSoftJsonSerializer = new Newtonsoft.Json.JsonSerializer();
}

[GlobalSetup(Target = nameof(Jil_))]
public void WarmupJil() => Jil_(); // workaround for https://github.com/dotnet/BenchmarkDotNet/issues/837

[BenchmarkCategory(Categories.ThirdParty)]
[Benchmark(Description = "Jil")]
public void Jil_()
Expand Down
8 changes: 3 additions & 5 deletions src/benchmarks/micro/Serializers/Json_ToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ namespace MicroBenchmarks.Serializers
[GenericTypeArguments(typeof(CollectionsOfPrimitives))]
public class Json_ToString<T>
{
private readonly T value;
private T value;

public Json_ToString() => value = DataGenerator.Generate<T>();

[GlobalSetup(Target = nameof(Jil_))]
public void WarmupJil() => Jil_(); // workaround for https://github.com/dotnet/BenchmarkDotNet/issues/837
[GlobalSetup]
public void Setup() => value = DataGenerator.Generate<T>();

[BenchmarkCategory(Categories.ThirdParty)]
[Benchmark(Description = "Jil")]
Expand Down
4 changes: 0 additions & 4 deletions src/benchmarks/micro/runtime/PacketTracer/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Concurrent;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using BenchmarkDotNet.Attributes;
Expand All @@ -20,9 +19,6 @@ public class SoA

private int[] rgbBuffer = new int[Width * 3 * Height]; // Each pixel has 3 fields (RGB)

[GlobalSetup]
public unsafe void Setup() => Render(); // run it once during the Setup to avoid https://github.com/dotnet/BenchmarkDotNet/issues/837s

[Benchmark]
public unsafe void Render()
{
Expand Down
8 changes: 2 additions & 6 deletions src/benchmarks/micro/runtime/perflab/BlockCopyPerf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ public class BlockCopyPerf
private byte[] bytes;

[Params(10, 100, 1000)]
public int numElements;
public int numElements;

[GlobalSetup]
public void Setup()
{
bytes = new byte[numElements * 2];
Buffer.BlockCopy(bytes, 0, bytes, numElements, numElements);
}
public void Setup() => bytes = new byte[numElements * 2];

[Benchmark]
public void CallBlockCopy() => Buffer.BlockCopy(bytes, 0, bytes, numElements, numElements);
Expand Down

0 comments on commit 6c3b2e3

Please sign in to comment.