Click here to Skip to main content
13,446,762 members (44,857 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 20 Aug 2012

Benchmark Code Blocks Easy

, 20 Aug 2012
Rate this:
Please Sign up or sign in to vote.
Benchmark code blocks easy

Have you been testing code speed like this?

var start = DateTime.Now;
int i;
for(i = 0; i < 1000; i++)
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 do in such a case? Write his own tools! :P That’s how BenchmarkNET appeared. Using BenchmarkNET, you can write the same thing as the 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. ;)


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


About the Author

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

You may also be interested in...


Comments and Discussions

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