/Functional.Benchmark

Provides functionality to perform and measure benchmarks in C#. The class contains methods to benchmark both synchronous and asynchronous operations.

Primary LanguageC#MIT LicenseMIT

Functional.Benchmark 🚀

Build Quality Gate Coverage NuGet latest version NuGet downloads

A simple C# class for benchmarking asynchronous and synchronous functions with a focus on functional programming.

Overview 📊

The FunctionalBenchmark class provides methods for benchmarking asynchronous and synchronous functions using the ValueStopwatch utility.

Usage 💡

Simply instantiate the FunctionalBenchmark class and use the provided methods for benchmarking your functions and actions.

var benchmark = new FunctionalBenchmark();

benchmark.BenchmarkAsync(async () => await YourAsyncFunction(), stopwatch => YourSyncStopwatchAction(stopwatch));
benchmark.Benchmark(() => YourSyncFunction(), stopwatch => YourSyncStopwatchAction(stopwatch));
// ... and more

// You also can inject in your dependencies
services.AddSingleton<IFunctionalBenchmark, FunctionalBenchmark>()

public static readonly IFunctionalBenchmark _functionalBenchmark;
// Use in your class
public MyClass(IFunctionalBenchmark functionalBenchmark)
{
    _functionalBenchmark = functionalBenchmark;
}

public async Task DoSomenthingAsync()
{
    await _functionalBenchmark.BenchmarkAsync(async () => await YourAsyncFunction(), 
        stopwatch => _logger.LogInformation($"TimeElapsed: {ElapsedTime}", stopwatch.GetElapsedTime().Milleseconds));
}

Contributing 👥

Contributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub. If you would like to contribute code, please fork the repository and submit a pull request.

License 📄

This project is licensed under the MIT License. See LICENSE for more information.

Support ☕

Buy Me A Coffee