Skip to content

Instantly share code, notes, and snippets.

@maftieu
Last active February 5, 2016 13:01
Show Gist options
  • Save maftieu/7fc4f253853a4f533d43 to your computer and use it in GitHub Desktop.
Save maftieu/7fc4f253853a4f533d43 to your computer and use it in GitHub Desktop.
Quick benchmark method
using System;
class Benchmarker
{
const int NB_RUN = 5;
public static void Benchmark(Action testMethod, string testName = null, bool blankRun = false)
{
if (string.IsNullOrEmpty(testName))
testName = testMethod.Method.Name;
if (blankRun)
testMethod();
var start = Environment.TickCount;
for (int i = 0; i < NB_RUN; i++)
{
testMethod();
}
var end = Environment.TickCount;
Console.WriteLine();
Console.WriteLine("{0} -> {1}", start, end);
Console.WriteLine("===> {0} -> {1:0.000} s <===", testName, (end - start) / 1000.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment