mirror of
https://github.com/aaru-dps/AaruBenchmark.git
synced 2025-12-16 19:24:36 +00:00
Add lambda benchmarks.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ namespace AaruBenchmark
|
||||
BenchmarkRunner.Run<Sha384Benchs>(config);
|
||||
BenchmarkRunner.Run<Sha512Benchs>(config);
|
||||
BenchmarkRunner.Run<SpamSumBenchs>(config);
|
||||
BenchmarkRunner.Run<LambdaBenchs>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user