Benchmark.It.Standard 1.2.2

dotnet add package Benchmark.It.Standard --version 1.2.2                
NuGet\Install-Package Benchmark.It.Standard -Version 1.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Benchmark.It.Standard" Version="1.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Benchmark.It.Standard --version 1.2.2                
#r "nuget: Benchmark.It.Standard, 1.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Benchmark.It.Standard as a Cake Addin
#addin nuget:?package=Benchmark.It.Standard&version=1.2.2

// Install Benchmark.It.Standard as a Cake Tool
#tool nuget:?package=Benchmark.It.Standard&version=1.2.2                

Benchmark.It

Simple easy .NET benchmarking for little bits of code. When you just really want to see if one method is actually faster than another.

Install

Run the following command in the Package Manager Console (NuGet).

PM> Install-Package Benchmark.It

Or clone and include BenchmarkIt.csproj directly

Use

Lets say you wanted to see if string.Contains was faster or slower than string.IndexOf. Simply write the following and have it printed out nicely for you to see.

Benchmark.This("string.Contains", () => "abcdef".Contains("ef"))
    .Against.This("string.IndexOf", () => "abcdef".IndexOf("ef"))
    .For(5)
    .Seconds().PrintComparison();
Name    Iterations      Percent
Name                                    Iterations          Percent                       
string.Contains                         23117812            100%                          
string.IndexOf                          10852501            46.9%

Or you wanted to see if a for loop was actually faster than a foreach loop (it is).

var values = Enumerable.Range(1, 100000).ToArray();
Benchmark.This("for.Count", () =>
{
    for (int i = 0; i < values.Count(); i++)
    {
        int x = values[i];
    }
})
.Against.This("for.Length", () =>
{
    for (int i = 0; i < values.Length; i++) {
        int x = values[i];
    }
})
.Against.This("foreach", () =>
{
    foreach (var x in values) ;
})
.For(10000)
.Iterations()
.PrintComparison();
Name                                    Milliseconds        Percent                       
for.Count                               34305               920.8%                        
for.Length                              3725                100%                          
foreach                                 4341                116.5%

And why stop there, you can add as many different methods as you want.

Benchmark.This("empty 1", () => { })
 .Against.This("empty 2", () => { })
 .Against.This("empty 3", () => { })
 .Against.This("empty 4", () => { })
 .Against.This("empty 5", () => { })
 .Against.This("empty 6", () => { })
 .For(1).Minutes().PrintComparison();

You can also just benchmark one method, and on top of that you can specify a number of warmpup loops to perform first.

Benchmark.This("string.Contains", () => "abcdef".Contains("ef"))
    .WithWarmup(1000)
    .For(5).Seconds()
    .PrintComparison();

TODO

  • Improve result print, clean it up etc.
  • Investigate manually unrolling the benchmark loops a bit
  • Speed up time loop
  • Generate graphs?
Product 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 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • 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.2.2 263 4/17/2022