nanoFramework.Benchmark 1.0.4

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.Benchmark --version 1.0.4                
NuGet\Install-Package nanoFramework.Benchmark -Version 1.0.4                
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="nanoFramework.Benchmark" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Benchmark --version 1.0.4                
#r "nuget: nanoFramework.Benchmark, 1.0.4"                
#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 nanoFramework.Benchmark as a Cake Addin
#addin nuget:?package=nanoFramework.Benchmark&version=1.0.4

// Install nanoFramework.Benchmark as a Cake Tool
#tool nuget:?package=nanoFramework.Benchmark&version=1.0.4                

nanoFramework.Benchmark

License #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework Benchmark repository

What is the .NET nanoFramework Benchmark

The nanoFramework.Benchmark tool helps you to measure and track performance of the nanoFramework code. You can easily turn normal method into benchmark by just adding one attribute!

Heavily inspired by BenchmarkDotNet.

Example bellow will:

  1. Run Setup method once before running any benchmark method.
  2. Run each benchmark method 10 time.
  3. Prepare data to be passed into each parses.
  4. Invoke ConsoleParser (prints data in console as table).
public class CompareObjectTypesBenchmark
{
    object[] array;

    [Setup]
    public void Setup()
    {
        array = new object[] {
                    (int)42,
                    (byte)42,
                    "This is a super string",
                    (ulong)42,
                    new Version(4, 2)
                };
    }

    [Benchmark]
    public void CompareByString()
    {
        for (int i = 0; i < array.Length; i++)
        {
            object obja = array.GetValue(i);
            var typea = obja.GetType();
            CompareUsingString(typea);
        }
    }

    [Benchmark]
    public void CompareUsingTypeofIf()
    {
        for (int i = 0; i < array.Length; i++)
        {
            object obja = array.GetValue(i);
            var typea = obja.GetType();
            CompareUsingTypeofIf(typea);
        }
    }

    [Benchmark]
    public void CompareUsingTypeofIfReturn()
    {
        for (int i = 0; i < array.Length; i++)
        {
            object obja = array.GetValue(i);
            var typea = obja.GetType();
            CompareUsingTypeofIfReturn(typea);
        }
    }
}

Output:

Console export: CompareObjectTypesBenchmark benchmark class.
| MethodName                 | ItterationCount | Mean  | Min   | Max   |
| -------------------------------------------------------------------- |
| CompareByString            | 10              | 10 ms | 10 ms | 10 ms |
| CompareUsingTypeofIf       | 10              | 3 ms  | 0 ms  | 10 ms |
| CompareUsingTypeofIfReturn | 10              | 5 ms  | 0 ms  | 10 ms |

Attributes

Class

IterationCount

Specify how many times each benchmark method needs to be invoked when running benchmark methods. Default is 10.


Logger

Sometimes you can try something that benchmark library does not support. In such situation, instead of debugging code, you may inject logger object.

DebugLogger

Wrapper around nanoFramework.Logging.Debug. Prints logs to console.

Methods

Setup

SetupAttribute is used to specify which method should be invoked only once before running benchmark methods. It can be used to initialize collections/objects etc. The execution time of setup method is not taken into account when calculating benchmark results.

Note, that setup method must be public and without parameters.

Benchmark

BenchmarkAttribute is used to specify which method should be invoked as benchmark.

Note, that benchmark method must be public and without parameters.


Parsers

You can specify parsers as attributes on class. Every parsers is invoked after benchmark run, so you can get results in multiple formats.

By default only ConsoleParser is applied.

New parses can be easily implement by creating new class and implementing IResultParses interface. Also new attribute needs to be

ConsoleParser

You can use CsvParserAttribute to add parser which prints data in console in table format.

Output example

Console export: CompareObjectTypesBenchmark benchmark class.
| MethodName                 | ItterationCount | Mean   | Min  | Max   |
| -------------------------------------------------------------------- |
| CompareByString            | 100             | 8.9 ms | 0 ms | 10 ms |
| CompareUsingTypeofIf       | 100             | 4.1 ms | 0 ms | 10 ms |
| CompareUsingTypeofIfReturn | 100             | 4.2 ms | 0 ms | 10 ms |
CsvParser

You can use CsvParserAttribute to add parser which prints data in console in CSV format.

Output example

CSV export: CompareObjectTypesBenchmark benchmark class.
MethodName;ItterationCount;Mean;Min;Max
CompareByString;100;8.9 ms;0 ms;10 ms
CompareUsingTypeofIf;100;4.1 ms;0 ms;10 ms
CompareUsingTypeofIfReturn;100;4.2 ms;0 ms;10 ms
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.80 129 10/24/2024
1.0.78 139 10/14/2024
1.0.77 118 10/3/2024
1.0.76 112 9/30/2024
1.0.75 252 8/29/2024
1.0.73 181 8/5/2024
1.0.72 123 7/25/2024
1.0.71 164 7/15/2024
1.0.68 300 6/3/2024
1.0.65 720 11/20/2023
1.0.62 249 11/10/2023
1.0.60 163 11/9/2023
1.0.58 134 11/9/2023
1.0.56 385 5/25/2023
1.0.53 217 5/4/2023
1.0.50 439 1/5/2023
1.0.47 326 12/29/2022
1.0.45 319 12/28/2022
1.0.43 340 12/27/2022
1.0.39 630 11/14/2022
1.0.37 438 10/29/2022
1.0.35 429 10/27/2022
1.0.33 440 10/26/2022
1.0.31 422 10/25/2022
1.0.29 447 10/24/2022
1.0.26 513 10/11/2022
1.0.24 461 10/8/2022
1.0.21 478 9/23/2022
1.0.19 465 9/17/2022
1.0.17 464 9/15/2022
1.0.15 434 9/6/2022
1.0.13 419 9/6/2022
1.0.8 421 9/5/2022
1.0.4 437 9/2/2022