Class BenchmarkWorkspace
- Namespace
- Codebelt.Extensions.BenchmarkDotNet
- Assembly
- Codebelt.Extensions.BenchmarkDotNet.dll
Provides a default implementation of IBenchmarkWorkspace for discovering and handling assemblies and their generated artifacts in BenchmarkDotNet.
public sealed class BenchmarkWorkspace : IBenchmarkWorkspace
- Inheritance
-
BenchmarkWorkspace
- Implements
Examples
The following example builds a default BenchmarkWorkspace against the current repository and walks through the two phases the workspace actually performs: discovering every *.Benchmarks.dll under the configured tuning folder for the current build configuration and target framework moniker, then moving the per-run results directory into the long-lived tuning directory once the benchmark run finishes.
using System;
using System.IO;
using Codebelt.Extensions.BenchmarkDotNet;
namespace MyBenchmarks;
public static class Program
{
public static void Main()
{
var repositoryPath = Directory.GetCurrentDirectory();
var options = new BenchmarkWorkspaceOptions
{
RepositoryPath = repositoryPath,
TargetFrameworkMoniker = "net10.0"
};
var workspace = new BenchmarkWorkspace(options);
// Discovers and loads every *.Benchmarks.dll that matches
// <RepositoryPath>/<RepositoryTuningFolder>/bin/<Debug|Release>/<TargetFrameworkMoniker>.
var assemblies = workspace.LoadBenchmarkAssemblies();
Console.WriteLine($"Loaded {assemblies.Length} benchmark assemblies from {repositoryPath}.");
// After a benchmark run, PostProcessArtifacts moves the per-run results directory
// into the configured tuning folder and removes the now-empty results directory.
workspace.PostProcessArtifacts();
}
}
Constructors
BenchmarkWorkspace(BenchmarkWorkspaceOptions)
Initializes a new instance of the BenchmarkWorkspace class with the specified options.
public BenchmarkWorkspace(BenchmarkWorkspaceOptions options)
Parameters
optionsBenchmarkWorkspaceOptionsThe BenchmarkWorkspaceOptions which configures repository paths, build modes and BenchmarkDotNet configuration.
Exceptions
- ArgumentNullException
optionscannot be null.- ArgumentException
optionsare not in a valid state.
Methods
GetReportsResultsPath(BenchmarkWorkspaceOptions)
Gets the path to the BenchmarkDotNet results directory
public static string GetReportsResultsPath(BenchmarkWorkspaceOptions options)
Parameters
optionsBenchmarkWorkspaceOptionsThe BenchmarkWorkspaceOptions which configures repository paths, build modes and BenchmarkDotNet configuration.
Returns
- string
A string containing the full path to the 'results' directory within the artifacts path.
Remarks
This path is constructed from the configured BenchmarkDotNet.Configs.IConfig.ArtifactsPath and the "results" subdirectory.
GetReportsTuningPath(BenchmarkWorkspaceOptions)
Gets the path to the tuning folder where final benchmark reports are stored.
public static string GetReportsTuningPath(BenchmarkWorkspaceOptions options)
Parameters
optionsBenchmarkWorkspaceOptionsThe BenchmarkWorkspaceOptions which configures repository paths, build modes and BenchmarkDotNet configuration.
Returns
- string
A string representing the full path to the tuning reports directory.
Remarks
This path is constructed from the configured BenchmarkDotNet.Configs.IConfig.ArtifactsPath and the RepositoryTuningFolder.
LoadBenchmarkAssemblies()
Loads benchmark assemblies discovered recursively in the tuning folder.
public Assembly[] LoadBenchmarkAssemblies()
Returns
Remarks
Assemblies are selected by matching the configured BenchmarkProjectSuffix, the build configuration (Debug/Release based on AllowDebugBuild), and the target framework moniker (TargetFrameworkMoniker).
Exceptions
- InvalidOperationException
Thrown when no matching assemblies could be loaded from the tuning folder. Ensure the tuning folder contains built benchmark assemblies for the configured build configuration and TFM.
PostProcessArtifacts()
Performs post-processing of artifacts produced by BenchmarkDotNet.
public void PostProcessArtifacts()
Remarks
This method moves files found in the BenchmarkDotNet artifacts "results" directory into the tuning folder under the configured artifacts path and then deletes the now-empty "results" directory.