DimonSmart.TinyBenchmark 2.1.0-beta

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of DimonSmart.TinyBenchmark.
dotnet add package DimonSmart.TinyBenchmark --version 2.1.0-beta
NuGet\Install-Package DimonSmart.TinyBenchmark -Version 2.1.0-beta
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="DimonSmart.TinyBenchmark" Version="2.1.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DimonSmart.TinyBenchmark --version 2.1.0-beta
#r "nuget: DimonSmart.TinyBenchmark, 2.1.0-beta"
#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 DimonSmart.TinyBenchmark as a Cake Addin
#addin nuget:?package=DimonSmart.TinyBenchmark&version=2.1.0-beta&prerelease

// Install DimonSmart.TinyBenchmark as a Cake Tool
#tool nuget:?package=DimonSmart.TinyBenchmark&version=2.1.0-beta&prerelease

TinyBenchmark

A Simple and User-Friendly Benchmarking Library

TinyBenchmark is a straightforward and user-friendly benchmarking library designed to facilitate a transparent comparison of execution times between two alternative functions. With the ability to parameterize functions using a single argument, TinyBenchmark makes it easy to assess performance differences.

Key Features:

  • Easy to Use: TinyBenchmark simplifies the process of benchmarking, ensuring you can quickly and effortlessly compare the execution times of different functions.
  • Parameterization: Easily parametrize functions with a single argument for more versatile testing.
  • Export Options: Benchmarking results can be exported in various formats, including:
    1. RAW Plain CSV: Generate raw data in CSV format for further analysis.
    2. Aggregate Data: Aggregate raw data for all benchmarking points or selectively for specified points of interest.
    3. Function Comparison Graphs: Visualize performance comparisons between functions within test classes.

TinyBenchmark is the ideal tool for gaining valuable insights into your code's performance. Whether you're a developer looking to optimize your code or simply curious about execution times, TinyBenchmark has you covered.

Usage Example

Test class

using DimonSmart.TinyBenchmark;
namespace DimonSmart.TinyBenchmarkTests;

public class ExampleClassTest
{
    [TinyBenchmarkParameter(1, 5, 10, 15, 20, 25)]
    public int BenchmarkParameter { get; set; }

    [TinyBenchmark]
    public void Function1(int parameter)
    {
        var guid = Guid.NewGuid();
    }

    [TinyBenchmark]
    public void Function2(int parameter)
    {
        for (var i = 0; i < parameter; i++)
        {
            var guid = Guid.NewGuid();
        }
    }
}

Benchmark Runner

public class TinyBenchmarkTestRunnerTest
{
    [Fact]
    public void RunAllBenchmarks()
    {
        TinyBenchmarkRunner
            .Create()
            .WithLogger(_output.WriteLine)
            .WithMaxRunExecutionTime(TimeSpan.FromSeconds(30), 100)
            .WithMinFunctionExecutionCount(100)
            .WithMaxFunctionExecutionCount(10000)
            .WithResultSubfolders(true)
            .Run(typeof(ExampleClassTest))
            .WithCsvExporter()
                .LimitResultLines(50)
                .SaveAllRawResults()
            .WithTableExporter()
                .SaveAllTablesResults()
            .WithGraphExporter()
                .ExportAllRawGraph(AscendingTimes)
                .ExportAllFunctionsCompareGraph(IncludeErrorMarks);
    }
}

Result examples

Function Comparison Graph:

This graph shows the performance comparison of your functions. The X-axis represents

[TinyBenchmarkParameter(1, 5, 10, 15, 20, 25)],

and the Y-axis represents function execution time. All functions are labeled with their names. Function comparision

Raw Execution Times

This graph is useful for ensuring that your functions provide stable values over time. Slightly fluctuated results are okay, but if you see something completely different, it could indicate the influence of parallel running processes on your measurement process. Function comparision

Raw Results (Ordered)

This graph also represents raw timing values but sorted. A typical graph shape should resemble an almost horizontal line with a sharp rise at the end. This sharp end corresponds to longer execution times, and the shorter this rising part, the better. Function comparision

Attributes

[TinyBenchmarkOnlyThisClassAttribute]

The TinyBenchmarkOnlyThisClassAttribute is designed for classes within the TinyBenchmark library. Applying this attribute to a class allows developers to streamline the test development process. It enables the easy exclusion of all benchmarks within a class except for the one currently under active development. By doing so, developers can maintain a clean and focused Git changes list, concentrating changes exclusively on the actively developed test.

[TinyBenchmarkAttribute]

The TinyBenchmarkAttribute is utilized for marking methods within benchmark classes. When applied, this attribute signals that the marked methods should be included in the benchmarking process. This attribute is crucial for pinpointing and measuring the performance of specific functions during benchmarking.

[TinyBenchmarkParameterAttribute]

The TinyBenchmarkParameterAttribute is used to designate parameters for functions under benchmark. Applied to properties within benchmark classes, this attribute allows developers to provide specific values for parameters. This flexibility facilitates the variation of inputs during benchmarking, enabling the measurement of performance under different scenarios.

[TinyBenchmarkRangeParameterAttribute]

The TinyBenchmarkRangeParameterAttribute is specifically tailored for defining range parameters for functions under benchmark. Applied to properties within benchmark classes, this attribute simplifies the specification of a range of values for parameters. This enhances flexibility in benchmarking scenarios, allowing developers to conduct tests across a specified range of inputs.

Usage Example

Consider the following example with a hypothetical benchmark class:

[TinyBenchmarkOnlyThisClass]
public class MyBenchmarkClass
{
    // Initialization logic here...

    [TinyBenchmarkRangeParameter(1, 60, 1)]
    public int BenchmarkParameter { get; set; }

    [TinyBenchmark]
    public void MyBenchmarkedMethod(int parameter)
    {
        // Benchmark logic for MyBenchmarkedMethod...
    }

    // Additional benchmark methods...
}

In this example, the MyBenchmarkClass class demonstrates the application of various TinyBenchmark attributes. These attributes contribute to a focused and effective benchmarking environment, enabling developers to streamline test development and measure performance with precision.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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
2.1.0-beta 64 2/18/2024
2.0.0-beta 74 2/5/2024
1.1.5-beta 181 12/7/2023
1.1.4-beta 107 11/28/2023
1.1.3-beta 127 11/6/2023