A simple C# class for benchmarking asynchronous and synchronous functions with a focus on functional programming.
The FunctionalBenchmark class provides methods for benchmarking asynchronous and synchronous functions using the ValueStopwatch utility.
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));
}
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.
This project is licensed under the MIT License. See LICENSE for more information.