diff --git a/Collections.Benchmarks.Core/BaselineVsActualBenchmarkBase.cs b/Collections.Benchmarks.Core/BaselineVsActualBenchmarkBase.cs index 4e69ef7..ec563f2 100644 --- a/Collections.Benchmarks.Core/BaselineVsActualBenchmarkBase.cs +++ b/Collections.Benchmarks.Core/BaselineVsActualBenchmarkBase.cs @@ -1,5 +1,6 @@ using BenchmarkDotNet.Attributes; using System.Numerics; +using System.Reflection; namespace Collections.Benchmarks.Core { @@ -34,18 +35,14 @@ namespace Collections.Benchmarks.Core public virtual int TestObjectCount { get; set; } = 0; public virtual int TestObjectCountForSlowMethods { get; private set; } - protected static Exception CreateUnknownBenchmarkTypeException(T benchmarkType) - { - return new InvalidOperationException($"******* UNKNOWN BENCHMARK TYPE {{{benchmarkType}}} *******"); - } - - protected static Exception CreateMethodNotFoundException(in string methodName, in string? className) - { - return new MethodAccessException($"******* METHOD {{{methodName}}} NOT FOUND IN CLASS {{{className}}} *******"); - } + protected static Exception CreateUnknownBenchmarkTypeException(T benchmarkType) => new InvalidOperationException($"******* UNKNOWN BENCHMARK TYPE {{{benchmarkType}}} *******"); + protected static Exception CreateMethodNotFoundException(in string methodName, in string? className) => new MethodAccessException($"******* METHOD {{{methodName}}} NOT FOUND IN CLASS {{{className}}} *******"); protected virtual void PrepareData(T benchmarkType) { } - protected virtual Action? GetTestMethod(TBenchmarkType? benchmarkType) => null; + protected virtual Action? GetTestMethod(TBenchmarkType? benchmarkType) + => (Action?)GetType().GetMethod(GetTestMethodName(benchmarkType), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)?.CreateDelegate(typeof(Action), this) ?? throw CreateMethodNotFoundException(GetTestMethodName(benchmarkType), GetType().FullName); + + protected virtual string GetTestMethodName(TBenchmarkType? benchmarkType) => $"{benchmarkType}"; [GlobalCleanup] public virtual void Cleanup() diff --git a/Collections.Benchmarks.Core/Collections.Benchmarks.Core.csproj b/Collections.Benchmarks.Core/Collections.Benchmarks.Core.csproj index badc0fc..acef3e5 100644 --- a/Collections.Benchmarks.Core/Collections.Benchmarks.Core.csproj +++ b/Collections.Benchmarks.Core/Collections.Benchmarks.Core.csproj @@ -7,24 +7,27 @@ Library true Collections.Benchmarks.Core - 0.0.1 + 0.0.4 Marek Lemańczyk N/A Collections.Benchmarks.Core Recyclable Array Pool List Sortable Sort Benchmark Benchmarks Collection Collections - `Recyclable.Collections.Benchmarks.Core` project is a basic open source framework for performance measurements based on various collection types like `RecyclableList<T>`, `RecyclableLongList<T>`, `List<T>`, `SortableList<T>`, `PriorityQueue<T>` & similar. + `Collections.Benchmarks.Core` project is a basic open source framework for performance measurements based on various collection types like `RecyclableList<T>`, `RecyclableLongList<T>`, `List<T>`, `SortableList<T>`, `PriorityQueue<T>` & similar. https://github.com/mlemanczyk/Collections.Benchmarks.Core https://github.com/mlemanczyk/Collections.Benchmarks.Core Marek Lemańczyk 2023 LICENSE.md README.md git - Initial version. + CollectionsBenchmarksBase renamed to DataDrivenBenchmarksBase. Small cleanup. AnyCPU;x64 - https://github.com/mlemanczyk/Collections.Benchmarks.Core/logo.png + logo.png + + PreserveNewest + PreserveNewest diff --git a/Collections.Benchmarks.Core/CollectionsBenchmarkType.cs b/Collections.Benchmarks.Core/CollectionsBenchmarkType.cs new file mode 100644 index 0000000..97820ea --- /dev/null +++ b/Collections.Benchmarks.Core/CollectionsBenchmarkType.cs @@ -0,0 +1,13 @@ +namespace Collections.Benchmarks.Core +{ + public enum CollectionsBenchmarkType + { + Unknown, Add_WithCapacity, Add, AddRange_WithCapacity, AddRangeWhenSourceIsArray, AddRangeWhenSourceIsIEnumerable, + AddRangeWhenSourceIsIList, AddRangeWhenSourceIsList, AddRangeWhenSourceIsSameType, BinarySearch_BestAndWorstCases, + Contains_FirstItems, Contains_LastItems, ConvertAll, Count, Create_WithCapacity, Create, Exists_BestAndWorstCases, + Find_BestAndWorstCases, FindAll_BestAndWorstCases, FindLast_BestAndWorstCases, FindLastIndex_BestAndWorstCases, + ForEach, GetItem, IndexOf_BestAndWorstCases,IndexOf_FirstItems, IndexOf_LastItems, LongCount, + Remove_FirstItems, Remove_LastItems, RemoveAt_FirstItems, RemoveAt_LastItems, + SetItem, VersionedForEach + } +} diff --git a/Collections.Benchmarks.Core/CollectionsBenchmarksBase.cs b/Collections.Benchmarks.Core/DataDrivenBenchmarksBase.cs similarity index 96% rename from Collections.Benchmarks.Core/CollectionsBenchmarksBase.cs rename to Collections.Benchmarks.Core/DataDrivenBenchmarksBase.cs index 181e4d4..ecb71fc 100644 --- a/Collections.Benchmarks.Core/CollectionsBenchmarksBase.cs +++ b/Collections.Benchmarks.Core/DataDrivenBenchmarksBase.cs @@ -5,7 +5,7 @@ using Recyclable.Collections; namespace Collections.Benchmarks.Core { [MemoryDiagnoser] - public class CollectionsBenchmarksBase : BaselineVsActualBenchmarkBase + public class DataDrivenBenchmarksBase : BaselineVsActualBenchmarkBase { protected int[]? _testObjects; protected int[] TestObjects => _testObjects ?? throw new NullReferenceException("Something is wrong and the field is not initialized"); @@ -62,7 +62,7 @@ namespace Collections.Benchmarks.Core base.PrepareData(benchmarkType); } - + public override void Cleanup() { Console.WriteLine("******* GLOBAL CLEANUP *******"); diff --git a/logo.png b/logo.png index 078521c..da81460 100644 Binary files a/logo.png and b/logo.png differ