diff --git a/src/RustyOptions.Benchmarks/Config.cs b/src/RustyOptions.Benchmarks/Config.cs new file mode 100644 index 0000000..352d1e9 --- /dev/null +++ b/src/RustyOptions.Benchmarks/Config.cs @@ -0,0 +1,15 @@ +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Reports; + +namespace RustyOptions.Benchmarks; + +internal sealed class Config : ManualConfig +{ + public Config() + { + AddDiagnoser(MemoryDiagnoser.Default); + SummaryStyle = SummaryStyle.Default.WithRatioStyle(RatioStyle.Percentage); + } +} \ No newline at end of file diff --git a/src/RustyOptions.Benchmarks/FirstOrNone.cs b/src/RustyOptions.Benchmarks/FirstOrNone.cs index de408ba..32d1362 100644 --- a/src/RustyOptions.Benchmarks/FirstOrNone.cs +++ b/src/RustyOptions.Benchmarks/FirstOrNone.cs @@ -5,14 +5,17 @@ namespace RustyOptions.Benchmarks; [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] +[Config(typeof(Config))] public class FirstOrNoneBenchmarks { + const int SIZE = 1000; + private readonly int[] intArray; private readonly List intList; public FirstOrNoneBenchmarks() { - intArray = [.. Enumerable.Range(1, 1000)]; + intArray = [.. Enumerable.Range(1, SIZE)]; intList = [.. intArray]; } @@ -46,36 +49,36 @@ public void FirstOrNoneListOld() _ = FirstOrNoneOld(intList); } - private static bool IsEven(int x) => (x & 1) == 0; + private static bool IsHalfway(int x) => x == SIZE / 2; [BenchmarkCategory("Predicate"), Benchmark] public void FirstOrNoneWithPredicateEnumerable() { - _ = IntEnumerable().FirstOrNone(IsEven); + _ = IntEnumerable().FirstOrNone(IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark] public void FirstOrNoneWithPredicateArray() { - _ = intArray.FirstOrNone(IsEven); + _ = intArray.FirstOrNone(IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark(Baseline = true)] public void FirstOrNoneWithPredicateArrayOld() { - _ = FirstOrNoneOld(intArray, IsEven); + _ = FirstOrNoneOld(intArray, IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark] public void FirstOrNoneWithPredicateList() { - _ = intList.FirstOrNone(IsEven); + _ = intList.FirstOrNone(IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark] public void FirstOrNoneWithPredicateListOld() { - _ = FirstOrNoneOld(intList, IsEven); + _ = FirstOrNoneOld(intList, IsHalfway); } private static Option FirstOrNoneOld(IEnumerable items) diff --git a/src/RustyOptions.Benchmarks/LastOrNone.cs b/src/RustyOptions.Benchmarks/LastOrNone.cs index b1589a4..6956c61 100644 --- a/src/RustyOptions.Benchmarks/LastOrNone.cs +++ b/src/RustyOptions.Benchmarks/LastOrNone.cs @@ -5,14 +5,17 @@ namespace RustyOptions.Benchmarks; [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] +[Config(typeof(Config))] public class LastOrNoneBenchmarks { + const int SIZE = 1000; + private readonly int[] intArray; private readonly List intList; public LastOrNoneBenchmarks() { - intArray = [.. Enumerable.Range(1, 1000)]; + intArray = [.. Enumerable.Range(1, SIZE)]; intList = [.. intArray]; } @@ -46,36 +49,36 @@ public void LastOrNoneListOld() _ = LastOrNoneOld(intList); } - private static bool IsEven(int x) => (x & 1) == 0; + private static bool IsHalfway(int x) => x == 500; [BenchmarkCategory("Predicate"), Benchmark] public void LastOrNoneWithPredicateEnumerable() { - _ = IntEnumerable().LastOrNone(IsEven); + _ = IntEnumerable().LastOrNone(IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark] public void LastOrNoneWithPredicateArray() { - _ = intArray.LastOrNone(IsEven); + _ = intArray.LastOrNone(IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark(Baseline = true)] public void LastOrNoneWithPredicateArrayOld() { - _ = LastOrNoneOld(intArray, IsEven); + _ = LastOrNoneOld(intArray, IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark] public void LastOrNoneWithPredicateList() { - _ = intList.LastOrNone(IsEven); + _ = intList.LastOrNone(IsHalfway); } [BenchmarkCategory("Predicate"), Benchmark] public void LastOrNoneWithPredicateListOld() { - _ = LastOrNoneOld(intList, IsEven); + _ = LastOrNoneOld(intList, IsHalfway); } private static Option LastOrNoneOld(IEnumerable items)