Friday, December 29, 2006

unshifty results...

Rick posted a comment and some thoughts on the validity of the performance numbers I posted a few months ago. He astutely noticed that the benchmarks for each language did slightly different things and generously offered up an excuse that all is fair in love and benchmarking. While it's tempting to be allowed to escape via this path, I think that correctness matters (even in benchmarks) and I was curious on whether the numbers would change with better Ruby code.

First, a comment. I was not knocking Ruby performance. My point at the time was that Ruby, being similar to Smalltalk, should be able to improve its performance using fairly well understood implementation techniques used in Smalltalk and many other OO language runtimes. As Ruby becomes more popular, I know there will be a focus on performance and Ruby developers will benefit. The comparisons here, just tell you where Ruby could be.

Two of the points Rick made, were 1) the benchmark code is wrong different between the languages and 2) the code doesn't use the proper Ruby array API, specifically calling out that using insert is overkill. I'm not a Ruby programmer yet despite all the pressure to take the Ruby plunge so I didn't notice the insert/pop discrepancy. Rick also noted that methods like push or unshift would be better for the type of work the benchmark was doing. The only way to find out is to bench it and besides, here I sit, on my couch, recovering from a brutal "cough your lungs out" cold with nothing better to do anyhow. This time, push/pop and shift/unshift are the candidates. I used the same original code from here with the loop counter changed to 500000 (so I don't have to wait 60 seconds+ per bench), and the inner operations changed to the various permutations of unshift/shift/push/pop.

unshift/shift 6.47 s
unshift/pop 6.97 s
push/pop 4.28 s
push/shift 6.05 s

Hmmmm, clearly the push/pop combination (which adds to the end and removes from the end) is the better choice for a pure stack and you would probably use push/shift for a queue. Ruby experts can chime in if there are better ways.

Now, let's try the old Smalltalk comparison. The equivalent methods in Smalltalk would be addFirst:/removeFirst/addLast:/removeLast. These numbers from same machine as above, same permutations using OrderedCollections.

addFirst/removeFirst 437 ms
addFirst/removeLast 468 ms
addLast/removeLast 375 ms
addLast/removeFirst 515 ms

So, for this case, I think Ruby has some opportunities to exploit which could help Ruby runtime performance. The one caveat is that I don't know enough about Ruby internals to tell if there is some super secret array semantics that makes it difficult to implement efficiently.

Can someone explain what Ruby is doing here that is taking the time ?

Thursday, December 14, 2006

Goat Shaving

Work has some annoying days... What else is new ? but I think there's hope. Thanks to Ken Walker , I think I found an opportunity for a new career.

<career rant deleted>

People make drums, drums require skins, skins need shaving, which leads to the "new career opportunity", becoming a "Goat Shaver" and making drums. Ken tuned me into this opportunity with his recent blog entry that includes shocking goat shaving pictures. Career goal, be the best darn goat shaver in history !

You can even learn more about goat shaving online. Of course, this is for live goats and Ken was shaving the skins of dead goats but that's just a detail. My favorite tip ? "Talk to other goat owners in your area and have a goat-shaving day". How am I supposed to find goat owners in my area ? I guess I could ask ... so if you own a goat and live in my area, drop me line.

Am I serious about goat shaving as a career ? Probably not. Was it worth it to pretend so I could have a blog entry called Goat Shaver ? Absolutely.

Anyhow, I sent out a goat shaving career change notice which apparently didn't appeal to any of my friends or co-workers. They suggested that instead we start a band, go on tour and call the band "The Goat Shavers". This is genius in it's purest form. This way we can be "Goat Shavers" with no actual goat shaving required, kind of like virtual goat shavers.

Virtual machines, virtual goats ... right up my alley,

Thursday, December 07, 2006

The 7 stages of benchmarks...

Inspired by Pat Mueller's recent historical journey, I dipped into my own archives and found this old chart from a presentation I did many years ago in which I apparently mocked benchmarking (we probably weren't doing so well at the time). I did modify it slightly by changing the background to white (from the horrid powerpoint one I had used) and I also removed the words that were under each figure so you could have some fun and invent your own. This is not a contest, but all suggestions welcome. I will repost an updated pic with tag lines added for the one which makes me laugh the most.

Note: these figures are straight from Powerpoint which includes these useful pictures (I wonder why?) as well as handy pre-filled in templates (it used to be a wizard) which help you "communicate bad news". Seems the creators of powerpoint have it all covered.