Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Benchmark code blocks easy

, 20 Aug 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Have you been testing code speed like this? Or maybe you’ve found the Stopwatch class and been happy with its superior time precision? Better, I’d say, but I’ve quite had it. Plus I needed to benchmark a local website and …Read more »

Have you been testing code speed like this?

var start = DateTime.Now;
int i;
for(i = 0; i < 1000; i++)
{
    DoSomething();
}
var stop = DateTime.Now;
var total = stop - start;
var timePerIteration = total.Ticks / i;

Or maybe you’ve found the Stopwatch class and been happy with its superior time precision?

Better, I’d say, but I’ve quite had it. Plus I needed to benchmark a local website and needed to test parallel requests (something similar to ab – ApacheBench)

What does a programmer in such a case? Writes his own tools! :P That’s how BenchmarkNET appeared. Using BenchmarkNET you can write the same thing as above only much shorter and with a better timing precision :

var result = Benchmark.Sequentially(() => DoSomething(), 1000);

Neat? That’s not all. The result can easily printed out to a console or inspected with a debugger :

Benchmarking an HTTP operation over 10 parallel threads, 100 times for each thread?

var dl2 = Benchmark.Parallel(new BenchmarkParams<WebClient>(c => c.DownloadString("http://localhost/"), 100), 10, () => new WebClient());

The project has been published as open source (LGPL license) on CodePlex. You can discuss it, file bugs, or even contribute to it.

Have fun and if you test it out, please leave some feedback!

Later edit : It seems some people already dig it ;)


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Andrei Ion Rînea
Software Developer (Senior) IBM, Business Analytics
Romania Romania
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 20 Aug 2012
Article Copyright 2012 by Andrei Ion Rînea
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid