John Lam 1997 — 2026

Lies, damn lies and benchmarks

I decided to run some very crude benchmarks using my Ruby / .NET bridge just to get a feel for where my code was in relation to the performance of other bridges. I know that my approach is correct and should yield excellent performance. There are, however, a number of optimizations that have yet to be implemented.

The benchmark that I’m using here is really attempting to isolate the interop performance of reading an integer from .NET and marshaling the result back to Ruby. I have a few more tricks up my sleeve for optimizing the performance of marshaling a value type back to Ruby from .NET that I haven’t implemented yet, so this number is likely to improve.

The C# code looks like:

ArrayList k = new ArrayList(); int r = 0;
for(int i = 0; i < 1000000000; ++i)
r += k.Count;

The Ruby code looks like:

a, b = ArrayList.new, 0
benchmark.times { b += a.Count }

I attempt to correct for Ruby loop overhead by subtracting the time taken to run this calculation:

m = 0
benchmark.times { m += 0 }

The C# code ran at a rate of 205M iterations / second. The Ruby code ran at a corrected rate of 3.2M iterations / second.

My bridge marshals an integer value type from .NET to Ruby at a rate that is 65X slower than a single register load. That’s not bad for a start.

By comparison, if you look at the SaltyPickle bridge that heavily relies on reflection, you’ll find that their cost is on the order of 18,000X slower. They also have the side-effect that there is a lot of increased pressure on the GC to collect all of the boxed integers that are used by Reflection. It’s unclear whether GC time is factored into their observed times.

I need to run a real performance study later on once my bridge matures a bit more. But I think things are already going pretty well when my bridge runs 275X faster than an existing bridge :)

2 archived reader comments

Rob Loach (2005/11/08)

Hi John, I met you at the Launch with Chris and just thought I’d say hi. I took a quick look at the stuff you did with the bridge and it perked my interested! It’s been pretty busy on the classes front (gotta feed the family), but when I get the chance, I’ll take a longer look at it and tell you what I think. Thanks a lot John, and I’ll talk to you later. Rob Loach

John Lam (2005/11/09)

Rob, It’s always fun to talk to students! Feel free to contact me later on about how this project is going.