mirror of
https://github.com/aziascreations/PB-MessagePack.git
synced 2026-11-24 18:28:44 +01:00
Added examples, Added performance tests, Updated readme
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// 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}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user