JPSoft.Benchmarker
1.0.0
dotnet add package JPSoft.Benchmarker --version 1.0.0
NuGet\Install-Package JPSoft.Benchmarker -Version 1.0.0
<PackageReference Include="JPSoft.Benchmarker" Version="1.0.0" />
paket add JPSoft.Benchmarker --version 1.0.0
#r "nuget: JPSoft.Benchmarker, 1.0.0"
// Install JPSoft.Benchmarker as a Cake Addin
#addin nuget:?package=JPSoft.Benchmarker&version=1.0.0
// Install JPSoft.Benchmarker as a Cake Tool
#tool nuget:?package=JPSoft.Benchmarker&version=1.0.0
JPSoft.Benchmarker
A small benchmarking API for .NET Standard
Introduction
JPSoft.Benchmark is based on a previous project called JPSoft.Profiling.
The goal, has it is for JPSoft.Profiling, is to provide a safe environment to perform benchmarking against a block of code, or several.
Getting Started
Simply do:
var recipe = Benchmarker.Build(
(builder) => builder.For("Recipe", // <= recipe name
() =>
{
var a = 1;
var b = 2 + a; // <= code to benchmark
})
.With((a) => a
.IterateFor(10000000) // <= settings;
.TimeoutOn(1000)));
var benchmark = Benchmarker.Run(recipe); // <= Execute
Or simpler:
var benchmark = Benchmarker.BuildAndRun(
(builder) => builder.For("Recipe", () =>
{
var a = 1;
var b = 2 + a;
})
.With((a) => a
.IterateFor(10000000)
.TimeoutOn(1000)));
Reuse settings:
Action<IRecipeSettingsBuilder> globalSettings = b => b.IterateFor(1000);
var benchmark1 = Benchmarker.BuildAndRun(
(builder) => builder.For("Recipe1", () =>
{/*Fancy recipe code*/}).With(globalSettings));
var benchmark2 = Benchmarker.BuildAndRun(
(builder) => builder.For("Recipe2", () =>
{/*Fancy recipe code*/}).With(globalSettings));
Or use defaults:
With()));
Set the defaults:
BenchmarkerDefaults.OverrideDefaultIterations(1000000);
BenchmarkerDefaults.OverrideDefaultTimeout(1000);
BenchmarkerDefaults.OverrideDefaultReport((b) => $"Recipe Name: {b.Recipe.Name}\nIsSuccess: {b.IsSuccess}\n");
And then consult the generated benchmark;
benchmark.IsSuccess;
benchmark.Milliseconds;
benchmark.IterationsPerMillisecond;
benchmark.MillisecondsPerIteration;
benchmark.TaskRunStatus;
benchmark.Exception;
Or use the reporting tool:
System.Console.WriteLine(benchmark.GetReport());
Prerequisites
Must be compatible with netstandard2.0
NuGet Packages
Install-Package JPSoft.Benchmarker
dotnet add package JPSoft.Benchmarker --version 1.0.0
Motivation
Premature optimization maybe the root of all evil but sometimes you just want to test the hell out of a code snippet or maybe an entire method.
I got tired of writing for loops
& stopWatch.Start()
to test my micro optimizations and this was a fun project to do.
Hope you guys enjoy it.
Author
- João Palma Sequeira - JMPSequeira
License
This project is licensed under the MIT License - see the LICENSE.txt file for details
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 1,058 | 2/18/2018 |
Initial Release