From ed11e42b480853d25d8eafc9e0fef13802fc17d2 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Thu, 13 Apr 2023 03:54:01 +0200 Subject: [PATCH] BoolOrComparePoc benchmarks added to confirm findings from RecyclableList.EnsureCapacity runs. --- .../POC/BoolOrComparePoc.Benchmarks.cs | 50 +++++++++++++++++++ Recyclable.Collections.Benchmarks/Program.cs | 1 + 2 files changed, 51 insertions(+) create mode 100644 Recyclable.Collections.Benchmarks/POC/BoolOrComparePoc.Benchmarks.cs diff --git a/Recyclable.Collections.Benchmarks/POC/BoolOrComparePoc.Benchmarks.cs b/Recyclable.Collections.Benchmarks/POC/BoolOrComparePoc.Benchmarks.cs new file mode 100644 index 0000000..61b0c8d --- /dev/null +++ b/Recyclable.Collections.Benchmarks/POC/BoolOrComparePoc.Benchmarks.cs @@ -0,0 +1,50 @@ +using BenchmarkDotNet.Attributes; +using System.Runtime.CompilerServices; + +namespace Recyclable.Collections.Benchmarks.POC +{ + [MemoryDiagnoser] + public class BoolOrComparePocBenchmarks + { + public static void Run() + { + var benchmark = new BoolOrComparePocBenchmarks(); + benchmark.Bool(); + benchmark.Compare(); + } + + private static void DoNothing(T result, [CallerMemberName] string? callerName = null) + { + //Console.WriteLine($"{callerName}: result = {result}"); + } + + private bool _testBool = true; + private int _blockSize = 8; + + [Benchmark(Baseline = false)] + public void Bool() + { + if (_testBool) + { + DoNothing(_testBool); + } + else + { + DoNothing(_testBool); + } + } + + [Benchmark(Baseline = false)] + public void Compare() + { + if (_blockSize >= RecyclableDefaults.MinPooledArrayLength) + { + DoNothing(_testBool); + } + else + { + DoNothing(_testBool); + } + } + } +} \ No newline at end of file diff --git a/Recyclable.Collections.Benchmarks/Program.cs b/Recyclable.Collections.Benchmarks/Program.cs index d7a156f..4bc71a0 100644 --- a/Recyclable.Collections.Benchmarks/Program.cs +++ b/Recyclable.Collections.Benchmarks/Program.cs @@ -42,6 +42,7 @@ internal class Program _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); + _ = BenchmarkRunner.Run(BenchmarkConfig); } private static void Main(string[] args)