Files
Chronos/tests/Titano.Data.Tests/Perf/PerfGate.cs
T
Claude 7170943c68 test(perf): opt-in gates for the 500k-photo library and the 100k-frame rebuild
Category perf, skipped unless TITANO_PERF=1. A synthetic library of 2,000
sequences and 500,000 frames (SQLite, and PostgreSQL when TITANO_TEST_PG is
set) must open the Library in under 1 s cold and answer every filter, search,
sort and next page in under 200 ms; a 100,000-frame archive adopted from real
files must rebuild from its sidecars, with and without the index snapshot,
into the identical index within the scaled 2-minute budget. perf.yml runs
them weekly and on demand against PostgreSQL 17 and writes the timings to the
job summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 22:35:30 +00:00

27 lines
846 B
C#

using System.Diagnostics;
namespace Titano.Data.Tests.Perf;
/// <summary>Timing helpers of the opt-in performance gates (<c>TITANO_PERF=1</c>, category <c>perf</c>).</summary>
internal static class PerfGate
{
public const string Variable = "TITANO_PERF";
public static async Task<double> TimeAsync(Func<Task> action)
{
var watch = Stopwatch.StartNew();
await action();
return watch.Elapsed.TotalMilliseconds;
}
/// <summary>Median of <paramref name="runs"/> timed runs after one untimed warm-up.</summary>
public static async Task<double> MedianAsync(Func<Task> action, int runs = 5)
{
await action();
var times = new double[runs];
for (var i = 0; i < runs; i++) times[i] = await TimeAsync(action);
Array.Sort(times);
return times[runs / 2];
}
}