Table of Contents

BenchmarkWorkspaceOptions Class

Definition

Namespace
Codebelt.Extensions.BenchmarkDotNet
Assemblies
Codebelt.Extensions.BenchmarkDotNet.dll
Source
src/Codebelt.Extensions.BenchmarkDotNet/BenchmarkWorkspaceOptions.cs

Configuration options for BenchmarkWorkspace.

public class BenchmarkWorkspaceOptions : IValidatableParameterObject, IPostConfigurableParameterObject, IParameterObject
Inheritance
BenchmarkWorkspaceOptions
Implements
Extension Methods

Examples

The following example configures a BenchmarkWorkspaceOptions instance with the repository layout and discovery knobs the workspace will use, then runs the two lifecycle methods that the workspace invokes before the benchmark run (PostConfigureOptions) and during construction (ValidateOptions). This is the same shape every consumer follows: build an options instance, optionally override one or more defaults, and let the workspace validate the state.

using System;
using Codebelt.Extensions.BenchmarkDotNet;

namespace MyBenchmarks;

public static class Program
{
    public static void Main()
    {
        var options = new BenchmarkWorkspaceOptions
        {
            // pin the workspace to a specific repository layout
            RepositoryPath = @"C:\Repos\MyBenchmarkRepo",
            RepositoryTuningFolder = "tuning",
            RepositoryReportsFolder = "reports",
            TargetFrameworkMoniker = "net10.0",
            BenchmarkProjectSuffix = "Benchmarks",
            AllowDebugBuild = false,
            SkipBenchmarksWithReports = true
        };

        // late-bind the BenchmarkDotNet artifacts path against the configured repository
        options.PostConfigureOptions();

        // throws InvalidOperationException if any required property is missing or whitespace
        options.ValidateOptions();

        Console.WriteLine($"ArtifactsPath: {options.Configuration.ArtifactsPath}");
    }
}

Remarks

The following table shows the initial property values for an instance of BenchmarkWorkspaceOptions.

PropertyInitial Value
RepositoryPathResolved runtime by filesystem, e.g. C:\Repos\MyBenchmarkRepo.
ConfigurationBenchmarkDotNet configured to use recommended settings as outlined in: https://github.com/dotnet/performance/blob/main/src/harness/BenchmarkDotNet.Extensions/RecommendedConfig.cs.
TargetFrameworkMonikerResolved runtime by reflection, e.g. net10.0.
RepositoryTuningFolderDefaultRepositoryTuningFolder
RepositoryReportsFolderDefaultRepositoryReportsFolder
BenchmarkProjectSuffixDefaultBenchmarkProjectSuffix
AllowDebugBuildfalse
SkipBenchmarksWithReportsfalse

Constructors

Name Description
BenchmarkWorkspaceOptions()

Initializes a new instance of the BenchmarkWorkspaceOptions class with sensible defaults.

Fields

Name Description
DefaultBenchmarkProjectSuffix

The default suffix used to identify benchmark projects.

DefaultRepositoryReportsFolder

The default folder name where benchmark reports are written relative to the repository path.

DefaultRepositoryTuningFolder

The default folder name used for tuning artifacts relative to the repository path.

Slim

A tuned BenchmarkDotNet.Jobs.Job preset that serves as a fast, reliable baseline for most benchmarks, balancing measurement accuracy with developer efficiency.

Properties

Name Description
AllowDebugBuild

Gets or sets a value indicating whether the benchmarks should be allowed to run using a Debug build.

BenchmarkProjectSuffix

Gets or sets the project name suffix used to identify benchmark projects.

Configuration

Gets or sets the BenchmarkDotNet.Configs.IConfig instance used by BenchmarkDotNet.

RepositoryPath

Gets or sets the root path of the repository where benchmark projects and reports live.

RepositoryReportsFolder

Gets or sets the folder name under RepositoryPath used to store generated reports.

RepositoryTuningFolder

Gets or sets the folder name under RepositoryPath used to store tuning artifacts.

SkipBenchmarksWithReports

Gets or sets a value indicating whether benchmarks that already have generated reports should be skipped during execution.

TargetFrameworkMoniker

Gets or sets the target framework moniker (TFM) string to be used for benchmark discovery and reporting.

Methods

Name Description
PostConfigureOptions()

Finalizes the configured options before use.

ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.