Benchmark.NET makes it easier to measure the execution time of a piece of code.

Internally it uses System.Diagnostics.Stopwatch so it is of higher precision that querying System.DateTime.Now.

Instead of :

var sw = Stopwatch.StartNew();
int i;
for(i = 0; i < 1000; i++)
var ticksPerIteration = sw.Elapsed.Ticks / i;

you can just :

var result = Benchmark.Sequentially(()=>TestSomePieceOfCode());

Also, you can do parallel benchmarks, useful when, for example, you are testing a remote service and see how it holds under a certain number of clients.

Samples included in code.

Last edited Mar 21, 2012 at 6:24 PM by andreir, version 3