Skip to content

Commit 6c3b2e3

Browse files
committed
there is no need for the warmup workaround anymore, dotnet/BenchmarkDotNet#1573 has solved the problem
1 parent 4146963 commit 6c3b2e3

File tree

5 files changed

+17
-37
lines changed

5 files changed

+17
-37
lines changed

src/benchmarks/micro/Serializers/Json_FromString.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,25 @@ namespace MicroBenchmarks.Serializers
1313
[GenericTypeArguments(typeof(CollectionsOfPrimitives))]
1414
public class Json_FromString<T>
1515
{
16-
private readonly T value;
1716
private string serialized;
1817

19-
public Json_FromString() => value = DataGenerator.Generate<T>();
20-
2118
[GlobalSetup(Target = nameof(Jil_))]
22-
public void SerializeJil()
23-
{
24-
serialized = Jil.JSON.Serialize<T>(value, Jil.Options.ISO8601);
25-
26-
Jil_(); // workaround for https://github.com/dotnet/BenchmarkDotNet/issues/837
27-
}
28-
29-
[GlobalSetup(Target = nameof(JsonNet_))]
30-
public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(value);
31-
32-
[GlobalSetup(Target = nameof(Utf8Json_))]
33-
public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(value);
19+
public void SetupJil() => serialized = Jil.JSON.Serialize<T>(DataGenerator.Generate<T>(), Jil.Options.ISO8601);
3420

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

25+
[GlobalSetup(Target = nameof(JsonNet_))]
26+
public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DataGenerator.Generate<T>());
27+
3928
[BenchmarkCategory(Categories.Runtime, Categories.Libraries, Categories.ThirdParty)]
4029
[Benchmark(Description = "JSON.NET")]
4130
public T JsonNet_() => Newtonsoft.Json.JsonConvert.DeserializeObject<T>(serialized);
4231

32+
[GlobalSetup(Target = nameof(Utf8Json_))]
33+
public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(DataGenerator.Generate<T>());
34+
4335
[BenchmarkCategory(Categories.ThirdParty)]
4436
[Benchmark(Description = "Utf8Json")]
4537
public T Utf8Json_() => Utf8Json.JsonSerializer.Deserialize<T>(serialized);

src/benchmarks/micro/Serializers/Json_ToStream.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ namespace MicroBenchmarks.Serializers
1616
[GenericTypeArguments(typeof(CollectionsOfPrimitives))]
1717
public class Json_ToStream<T>
1818
{
19-
private readonly T value;
19+
private T value;
2020

21-
private readonly MemoryStream memoryStream;
22-
private readonly StreamWriter streamWriter;
21+
private MemoryStream memoryStream;
22+
private StreamWriter streamWriter;
2323

2424
private DataContractJsonSerializer dataContractJsonSerializer;
2525
private Newtonsoft.Json.JsonSerializer newtonSoftJsonSerializer;
2626

27-
public Json_ToStream()
27+
[GlobalSetup]
28+
public void Setup()
2829
{
2930
value = DataGenerator.Generate<T>();
3031

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

39-
[GlobalSetup(Target = nameof(Jil_))]
40-
public void WarmupJil() => Jil_(); // workaround for https://github.com/dotnet/BenchmarkDotNet/issues/837
41-
4240
[BenchmarkCategory(Categories.ThirdParty)]
4341
[Benchmark(Description = "Jil")]
4442
public void Jil_()

src/benchmarks/micro/Serializers/Json_ToString.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ namespace MicroBenchmarks.Serializers
1313
[GenericTypeArguments(typeof(CollectionsOfPrimitives))]
1414
public class Json_ToString<T>
1515
{
16-
private readonly T value;
16+
private T value;
1717

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

2321
[BenchmarkCategory(Categories.ThirdParty)]
2422
[Benchmark(Description = "Jil")]

src/benchmarks/micro/runtime/PacketTracer/Render.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Concurrent;
76
using System.Runtime.Intrinsics;
87
using System.Runtime.Intrinsics.X86;
98
using BenchmarkDotNet.Attributes;
@@ -20,9 +19,6 @@ public class SoA
2019

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

23-
[GlobalSetup]
24-
public unsafe void Setup() => Render(); // run it once during the Setup to avoid https://github.com/dotnet/BenchmarkDotNet/issues/837s
25-
2622
[Benchmark]
2723
public unsafe void Render()
2824
{

src/benchmarks/micro/runtime/perflab/BlockCopyPerf.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ public class BlockCopyPerf
1313
private byte[] bytes;
1414

1515
[Params(10, 100, 1000)]
16-
public int numElements;
16+
public int numElements;
1717

1818
[GlobalSetup]
19-
public void Setup()
20-
{
21-
bytes = new byte[numElements * 2];
22-
Buffer.BlockCopy(bytes, 0, bytes, numElements, numElements);
23-
}
19+
public void Setup() => bytes = new byte[numElements * 2];
2420

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

0 commit comments

Comments
 (0)