Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
namespace StellaOps.Bench.LinkNotMerge.Vex;
|
|
|
|
internal readonly record struct DurationStatistics(double MeanMs, double P95Ms, double MaxMs)
|
|
{
|
|
public static DurationStatistics From(IReadOnlyList<double> values)
|
|
{
|
|
if (values.Count == 0)
|
|
{
|
|
return new DurationStatistics(0, 0, 0);
|
|
}
|
|
|
|
var sorted = values.ToArray();
|
|
Array.Sort(sorted);
|
|
|
|
var total = 0d;
|
|
foreach (var value in values)
|
|
{
|
|
total += value;
|
|
}
|
|
|
|
var mean = total / values.Count;
|
|
var p95 = Percentile(sorted, 95);
|
|
var max = sorted[^1];
|
|
|
|
return new DurationStatistics(mean, p95, max);
|
|
}
|
|
|
|
private static double Percentile(IReadOnlyList<double> sorted, double percentile)
|
|
{
|
|
if (sorted.Count == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var rank = (percentile / 100d) * (sorted.Count - 1);
|
|
var lower = (int)Math.Floor(rank);
|
|
var upper = (int)Math.Ceiling(rank);
|
|
var weight = rank - lower;
|
|
|
|
if (upper >= sorted.Count)
|
|
{
|
|
return sorted[lower];
|
|
}
|
|
|
|
return sorted[lower] + weight * (sorted[upper] - sorted[lower]);
|
|
}
|
|
}
|
|
|
|
internal readonly record struct ThroughputStatistics(double MeanPerSecond, double MinPerSecond)
|
|
{
|
|
public static ThroughputStatistics From(IReadOnlyList<double> values)
|
|
{
|
|
if (values.Count == 0)
|
|
{
|
|
return new ThroughputStatistics(0, 0);
|
|
}
|
|
|
|
var total = 0d;
|
|
var min = double.MaxValue;
|
|
|
|
foreach (var value in values)
|
|
{
|
|
total += value;
|
|
min = Math.Min(min, value);
|
|
}
|
|
|
|
var mean = total / values.Count;
|
|
return new ThroughputStatistics(mean, min);
|
|
}
|
|
}
|
|
|
|
internal readonly record struct AllocationStatistics(double MaxAllocatedMb)
|
|
{
|
|
public static AllocationStatistics From(IReadOnlyList<double> values)
|
|
{
|
|
var max = 0d;
|
|
foreach (var value in values)
|
|
{
|
|
max = Math.Max(max, value);
|
|
}
|
|
|
|
return new AllocationStatistics(max);
|
|
}
|
|
}
|