Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/Beutl.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Reflection;

using BenchmarkDotNet.Running;
using Beutl.Benchmarks.Rendering;

// Select a benchmark via `-- --filter <pattern>`; no args shows an interactive picker.
BenchmarkSwitcher.FromAssembly(Assembly.GetExecutingAssembly()).Run(args);
return 0;
3 changes: 3 additions & 0 deletions tests/Beutl.Benchmarks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Beutl.UnitTests")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Exporters.Json;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;

namespace Beutl.Benchmarks.Rendering;

/// <summary>
/// Shared BenchmarkDotNet policy for paired persistent-lifetime render-pipeline measurements.
/// Renderer warm-up and output/counter verification remain GlobalSetup responsibilities of the benchmark class.
/// </summary>
internal sealed class RenderPipelineBenchmarkConfig : ManualConfig
{
public const string ArtifactsPathEnvironmentVariable = "BEUTL_RENDER_BENCHMARK_ARTIFACTS";

public const string CountersPathEnvironmentVariable = "BEUTL_RENDER_BENCHMARK_COUNTERS";

public const string OutputBlobsPathEnvironmentVariable = "BEUTL_RENDER_BENCHMARK_OUTPUT_BLOBS";

public const int SetupWarmupFrameCount = 5;

public const int BenchmarkWarmupCount = 3;

public const int BenchmarkIterationCount = 15;

public const int BenchmarkLaunchCount = 1;

public const int BenchmarkInvocationCount = 1;

public const int BenchmarkUnrollFactor = 1;

public const string BenchmarkJobId = "RenderPipeline";

public static string ExpectedJobDisplay =>
$"{BenchmarkJobId}(InvocationCount={BenchmarkInvocationCount}, "
+ $"IterationCount={BenchmarkIterationCount}, LaunchCount={BenchmarkLaunchCount}, "
+ $"RunStrategy={RunStrategy.Monitoring}, UnrollFactor={BenchmarkUnrollFactor}, "
+ $"WarmupCount={BenchmarkWarmupCount})";

public const string LifetimeContract =
"persistent-root-pipeline-and-version-available-structural-program-render-cache-target-pool-state";

public const string RequestShapeContract = "complete-target-surface-request-with-rgba16f-readback";

public RenderPipelineBenchmarkConfig()
{
AddJob(Job.Default
.WithId(BenchmarkJobId)
.WithStrategy(RunStrategy.Monitoring)
.WithLaunchCount(BenchmarkLaunchCount)
.WithWarmupCount(BenchmarkWarmupCount)
.WithIterationCount(BenchmarkIterationCount)
.WithInvocationCount(BenchmarkInvocationCount)
.WithUnrollFactor(BenchmarkUnrollFactor));
AddDiagnoser(MemoryDiagnoser.Default);
AddColumnProvider(DefaultColumnProviders.Instance);
AddLogger(ConsoleLogger.Default);
AddExporter(JsonExporter.Full);

string? artifactsPath = Environment.GetEnvironmentVariable(ArtifactsPathEnvironmentVariable);
if (!string.IsNullOrWhiteSpace(artifactsPath))
{
ArtifactsPath = Path.GetFullPath(artifactsPath);
}

string? countersPath = Environment.GetEnvironmentVariable(CountersPathEnvironmentVariable);
if (string.IsNullOrWhiteSpace(countersPath))
{
string root = !string.IsNullOrWhiteSpace(artifactsPath)
? Path.GetFullPath(artifactsPath)
: Path.GetFullPath("BenchmarkDotNet.Artifacts");
Environment.SetEnvironmentVariable(
CountersPathEnvironmentVariable,
Path.Combine(root, "render-pipeline-counters"));
}
}

public static string GetCountersPath()
{
string? value = Environment.GetEnvironmentVariable(CountersPathEnvironmentVariable);
return !string.IsNullOrWhiteSpace(value)
? Path.GetFullPath(value)
: throw new InvalidOperationException(
$"{CountersPathEnvironmentVariable} was not initialized by the benchmark configuration.");
}

public static string? GetOutputBlobsPath()
{
string? value = Environment.GetEnvironmentVariable(OutputBlobsPathEnvironmentVariable);
return string.IsNullOrWhiteSpace(value) ? null : Path.GetFullPath(value);
}
}
Loading