Tag Archives: benchmark

Benchmark code blocks easy

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! 😛 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 😉

Random performance findings

TL;DR version :

Upon a curiosity of mine I found out that WCF with basicHttpBinding can be easily beaten (performance-wise) by plain-old ASP.NET even if stripped down of transactions, reliability, security etc. (1500 req/sec vs  800 req/sec)

Also SQL Server Express can handle 1300 inserts per second easily and up to 4300 queries per second just as well. This on a 6+ million rows table and stored on the hard disk not in RAM.

Long version :

A few days ago I was thinking how I implemented a certain web service a few years ago, a few employers ago. Although it was quite fast and efficient it wasn’t scalable. I, then, thought how I should have implemented it.

The web service had to receive an incoming (public) HTTP request, check for a visitor cookie. If there was a visitor-identifying cookie it would check against a data store (in-memory dictionary at that time) to see if that visitor answered.

It was about inviting visitors of certain sites to an on-line survey. A new visitor would be presented with a pop-up box having a “yes”, a “no” and “X” (close) button.

The business rules stated that if the visitor answered yes, the answer would be stored, the pop-up would close and then a new tab/window would appear with the survey. If the visitor answered no, then the same things would happen except opening the survey. If the visitor closed the pop-up, the next time the pop-up would appear again. If the visitor closed three times the pop-up then (s)he wouldn’t be bothered anymore with the invitation.

Read more »