diff --git a/src/benchmarks/micro/Serializers/Json_FromString.cs b/src/benchmarks/micro/Serializers/Json_FromString.cs index 503439511e..82033935ea 100644 --- a/src/benchmarks/micro/Serializers/Json_FromString.cs +++ b/src/benchmarks/micro/Serializers/Json_FromString.cs @@ -13,33 +13,25 @@ namespace MicroBenchmarks.Serializers [GenericTypeArguments(typeof(CollectionsOfPrimitives))] public class Json_FromString { - private readonly T value; private string serialized; - public Json_FromString() => value = DataGenerator.Generate(); - [GlobalSetup(Target = nameof(Jil_))] - public void SerializeJil() - { - serialized = Jil.JSON.Serialize(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(DataGenerator.Generate(), Jil.Options.ISO8601); [BenchmarkCategory(Categories.ThirdParty)] [Benchmark(Description = "Jil")] public T Jil_() => Jil.JSON.Deserialize(serialized, Jil.Options.ISO8601); + [GlobalSetup(Target = nameof(JsonNet_))] + public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DataGenerator.Generate()); + [BenchmarkCategory(Categories.Runtime, Categories.Libraries, Categories.ThirdParty)] [Benchmark(Description = "JSON.NET")] public T JsonNet_() => Newtonsoft.Json.JsonConvert.DeserializeObject(serialized); + [GlobalSetup(Target = nameof(Utf8Json_))] + public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(DataGenerator.Generate()); + [BenchmarkCategory(Categories.ThirdParty)] [Benchmark(Description = "Utf8Json")] public T Utf8Json_() => Utf8Json.JsonSerializer.Deserialize(serialized); diff --git a/src/benchmarks/micro/Serializers/Json_ToStream.cs b/src/benchmarks/micro/Serializers/Json_ToStream.cs index 9617e2560d..7a2def7ebd 100644 --- a/src/benchmarks/micro/Serializers/Json_ToStream.cs +++ b/src/benchmarks/micro/Serializers/Json_ToStream.cs @@ -16,15 +16,16 @@ namespace MicroBenchmarks.Serializers [GenericTypeArguments(typeof(CollectionsOfPrimitives))] public class Json_ToStream { - 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(); @@ -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_() diff --git a/src/benchmarks/micro/Serializers/Json_ToString.cs b/src/benchmarks/micro/Serializers/Json_ToString.cs index bba07c8a1f..5dc00fcde7 100644 --- a/src/benchmarks/micro/Serializers/Json_ToString.cs +++ b/src/benchmarks/micro/Serializers/Json_ToString.cs @@ -13,12 +13,10 @@ namespace MicroBenchmarks.Serializers [GenericTypeArguments(typeof(CollectionsOfPrimitives))] public class Json_ToString { - private readonly T value; + private T value; - public Json_ToString() => value = DataGenerator.Generate(); - - [GlobalSetup(Target = nameof(Jil_))] - public void WarmupJil() => Jil_(); // workaround for https://github.com/dotnet/BenchmarkDotNet/issues/837 + [GlobalSetup] + public void Setup() => value = DataGenerator.Generate(); [BenchmarkCategory(Categories.ThirdParty)] [Benchmark(Description = "Jil")] diff --git a/src/benchmarks/micro/runtime/PacketTracer/Render.cs b/src/benchmarks/micro/runtime/PacketTracer/Render.cs index 9aa07f7e69..3e98a3e345 100644 --- a/src/benchmarks/micro/runtime/PacketTracer/Render.cs +++ b/src/benchmarks/micro/runtime/PacketTracer/Render.cs @@ -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; @@ -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() { diff --git a/src/benchmarks/micro/runtime/perflab/BlockCopyPerf.cs b/src/benchmarks/micro/runtime/perflab/BlockCopyPerf.cs index 98482c0ec2..a79cd46a0e 100644 --- a/src/benchmarks/micro/runtime/perflab/BlockCopyPerf.cs +++ b/src/benchmarks/micro/runtime/perflab/BlockCopyPerf.cs @@ -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);