Last active
February 5, 2016 13:01
-
-
Save maftieu/7fc4f253853a4f533d43 to your computer and use it in GitHub Desktop.
Quick benchmark method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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