Table of Contents

Class BenchmarkContext

Namespace
Codebelt.Extensions.BenchmarkDotNet.Console
Assembly
Codebelt.Extensions.BenchmarkDotNet.Console.dll

Represents the command-line context for a benchmark run.

public class BenchmarkContext
Inheritance
BenchmarkContext

Examples

The following example constructs a BenchmarkContext from the command-line arguments passed to the entry point. When the host resolves BenchmarkContext from the service provider, it inspects Args.Length to decide whether to run every benchmark in every loaded assembly (BenchmarkRunner.Run) or to forward the args to BenchmarkSwitcher for selective execution. A null array is normalized to an empty array so downstream code never has to guard against null.

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

namespace MyBenchmarks;

public static class Program
{
    public static void Main(string[] args)
    {
        var context = new BenchmarkContext(args);
        // context.Args is the same array passed to Main, or an empty array when args is null
        Console.WriteLine($"BenchmarkContext received {context.Args.Length} argument(s).");
        foreach (var arg in context.Args)
        {
            Console.WriteLine($"  - {arg}");
        }
    }
}

Constructors

BenchmarkContext(string[])

Initializes a new instance of the BenchmarkContext class.

public BenchmarkContext(string[] args)

Parameters

args string[]

The command-line arguments passed to the BenchmarkProgram.

Properties

Args

Gets the command-line arguments passed to the BenchmarkProgram.

public string[] Args { get; }

Property Value

string[]

The command-line arguments.