Table of Contents

BenchmarkProgram Class

Definition

Namespace
Codebelt.Extensions.BenchmarkDotNet.Console
Assemblies
Codebelt.Extensions.BenchmarkDotNet.Console.dll
Source
src/Codebelt.Extensions.BenchmarkDotNet.Console/BenchmarkProgram.cs

Entry point helper for hosting and running benchmarks using BenchmarkDotNet.

public class BenchmarkProgram : MinimalConsoleProgram<BenchmarkProgram>
Inheritance
BenchmarkProgram
Inherited Members

Examples

The following example shows the typical Program.cs of a benchmark host project: the entry point forwards the command-line arguments to BenchmarkProgram.RunAsync and supplies a setup delegate that customizes the resolved BenchmarkWorkspaceOptions before the host is built. BenchmarkProgram derives from Codebelt.Bootstrapper.Console.MinimalConsoleProgram<BenchmarkProgram>, so the Main plumbing — host configuration, service registration, lifecycle — is inherited; the only thing the host project has to write is the call site and the workspace configuration.

using System.Threading.Tasks;
using Codebelt.Extensions.BenchmarkDotNet;
using Codebelt.Extensions.BenchmarkDotNet.Console;

namespace MyBenchmarks;

public static class Program
{
    // minimal benchmark host: forwards args into the auto-discovered benchmark workspace
    public static Task Main(string[] args) => BenchmarkProgram.RunAsync(args, setup: options =>
    {
        options.BenchmarkProjectSuffix = "MyBench";
        options.AllowDebugBuild = false;
        options.SkipBenchmarksWithReports = true;
    });
}

Properties

Name Description
BuildConfiguration

Gets the build configuration of the entry assembly.

IsDebugBuild

Gets a value indicating whether the entry assembly was built in Debug configuration.

Methods

Name Description
Run(string[], Action<BenchmarkWorkspaceOptions>)

Runs benchmarks using the default BenchmarkWorkspace implementation.

Run(string[], Action<IServiceCollection>, Action<BenchmarkWorkspaceOptions>)

Runs benchmarks using the default BenchmarkWorkspace implementation.

RunAsync(IServiceProvider, CancellationToken)

Runs the actual benchmarks as envisioned by BenchmarkDotNet.

RunAsync(string[], Action<BenchmarkWorkspaceOptions>)

Runs benchmarks asynchronously using the default BenchmarkWorkspace implementation.

RunAsync(string[], Action<IServiceCollection>, Action<BenchmarkWorkspaceOptions>)

Runs benchmarks asynchronously using the default BenchmarkWorkspace implementation.

RunAsync<TWorkspace>(string[], Action<BenchmarkWorkspaceOptions>)

Runs benchmarks asynchronously using a custom implementation of IBenchmarkWorkspace.

RunAsync<TWorkspace>(string[], Action<IServiceCollection>, Action<BenchmarkWorkspaceOptions>)

Runs benchmarks asynchronously using a custom implementation of IBenchmarkWorkspace.

Run<TWorkspace>(string[], Action<BenchmarkWorkspaceOptions>)

Runs benchmarks using a custom implementation of IBenchmarkWorkspace.

Run<TWorkspace>(string[], Action<IServiceCollection>, Action<BenchmarkWorkspaceOptions>)

Runs benchmarks using a custom implementation of IBenchmarkWorkspace.

See Also