mirror of
https://github.com/aziascreations/PB-MessagePack.git
synced 2026-11-03 17:01:24 +01:00
9facb66ee8
Co-Authored-By: Claude <noreply@anthropic.com>
24 lines
693 B
C#
24 lines
693 B
C#
// Shared by the .NET performance tests, see `_PerfTesting.pbi` for the output format.
|
|
using System.Diagnostics;
|
|
|
|
static class Perf
|
|
{
|
|
const int Runs = 5;
|
|
|
|
// Runs `function` once to warm up, then `Runs` times, and prints its median.
|
|
public static void Run(string scenario, long operations, Func<long> function)
|
|
{
|
|
long check = function();
|
|
var times = new double[Runs];
|
|
for (int i = 0; i < Runs; i++)
|
|
{
|
|
var stopwatch = Stopwatch.StartNew();
|
|
check = function();
|
|
times[i] = stopwatch.Elapsed.TotalMilliseconds;
|
|
}
|
|
Array.Sort(times);
|
|
double median = times[Runs / 2];
|
|
Console.WriteLine($"dotnet,{scenario},{median:F1},{median * 1_000_000 / operations:F1},{check}");
|
|
}
|
|
}
|