Skip to content

Instantly share code, notes, and snippets.

@gladiatorAsh
Created May 23, 2018 04:43
Show Gist options
  • Save gladiatorAsh/57045f27358ffd0ba2441a01068d20d1 to your computer and use it in GitHub Desktop.
Save gladiatorAsh/57045f27358ffd0ba2441a01068d20d1 to your computer and use it in GitHub Desktop.
Simple Measurement in C#
private static void Measure(string what, int reps, Action action){
action(); //Warmup
double[] results=new double[reps];
for(int i=0;i<reps;i++){
StopWatch sw= StopWatch.StartNew();
action();
results[i]=sw.Elapsed.TotalMilliseconds;
}
Console.WriteLine("{0} - AVG = {1}, {2} = MIN, {3} = MAX",
what, results.Average(), results.Min(),rsults.Max());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment