Add lambda benchmarks.

This commit is contained in:
2024-05-04 12:37:44 +01:00
parent 2bcba3f8c2
commit 1d35f2889c
2 changed files with 45 additions and 0 deletions

View File

@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
@@ -802,4 +805,45 @@ namespace AaruBenchmark
public void AaruNative() => throw new NotImplementedException();
#endif
}
[SimpleJob(RuntimeMoniker.NetCoreApp31, baseline: true)]
[Core31RosettaJob]
[Core31WoA]
[Core31Arm]
[SimpleJob(RuntimeMoniker.Net80)]
[SimpleJob(RuntimeMoniker.NativeAot80)]
[MemoryDiagnoser(false)]
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD", "Alloc Ratio")]
[SuppressMessage("ReSharper", "ConvertClosureToMethodGroup")]
[SuppressMessage("ReSharper", "LambdaExpressionCanBeMadeStatic")]
[SuppressMessage("ReSharper", "MemberCanBeMadeStatic.Local")]
// Windows only
// [NativeMemoryProfiler]
public class LambdaBenchs
{
static readonly IEnumerable<int> ListOfInts = Enumerable.Range(1, 10_000).ToList();
[Benchmark]
public int Lambda_Static() => ListOfInts.Count(x => ConditionStatic(x));
[Benchmark]
public int MethodGroup_Static() => ListOfInts.Count(ConditionStatic);
static bool ConditionStatic(int value) => value > 10;
[Benchmark]
public int Lambda_Instance() => ListOfInts.Count(x => ConditionInstance(x));
[Benchmark]
public int MethodGroup_Instance() => ListOfInts.Count(ConditionInstance);
bool ConditionInstance(int value) => value > 10;
[Benchmark]
public int Anonymous_Instance() => ListOfInts.Count(x => x > 10);
[Benchmark]
public int Anonymous_Static() => ListOfInts.Count(static x => x > 10);
}
}

View File

@@ -43,6 +43,7 @@ namespace AaruBenchmark
BenchmarkRunner.Run<Sha384Benchs>(config);
BenchmarkRunner.Run<Sha512Benchs>(config);
BenchmarkRunner.Run<SpamSumBenchs>(config);
BenchmarkRunner.Run<LambdaBenchs>(config);
}
}
}