using System.Runtime.InteropServices; namespace ProjectQuint.Probes; public sealed record CoreBenchmarkReport(int SchemaVersion, bool Complete, DateTimeOffset MeasuredAtUtc, string Runtime, string OperatingSystem, string Architecture, int ProcessorCount, int Notes, int Events, uint Seed, int FrameRate, int WarmupIterations, int RequestedIterations, ReplayObservation[] Samples); public static class CoreBenchmark { public static CoreBenchmarkReport Run(int notes, uint seed, int frameRate, int iterations, Action checkpoint) { if (iterations < 1 || iterations > 100) throw new ArgumentOutOfRangeException(nameof(iterations), "Use 1 to 100 iterations."); var workload = SyntheticWorkload.Create(notes, seed); const int warmups = 3; JudgementSnapshot expected = default; for (var index = 0; index < warmups; index++) expected = ReplayRunner.Run(workload, frameRate).Judgement; var samples = new List(iterations); var measuredAt = DateTimeOffset.UtcNow; for (var index = 0; index < iterations; index++) { var sample = ReplayRunner.Run(workload, frameRate); if (sample.Judgement != expected || !sample.Judgement.Finished) throw new InvalidOperationException("The benchmark replay diverged from its warmup result."); samples.Add(sample); checkpoint(Report(false)); } return Report(true); CoreBenchmarkReport Report(bool complete) => new(1, complete, measuredAt, RuntimeInformation.FrameworkDescription, System.OperatingSystem.IsMacOS() ? "macOS" : System.OperatingSystem.IsLinux() ? "Linux" : System.OperatingSystem.IsWindows() ? "Windows" : "Other", RuntimeInformation.ProcessArchitecture.ToString(), Environment.ProcessorCount, notes, workload.Events.Length, seed, frameRate, warmups, iterations, samples.ToArray()); } }