Hmmmmm
I’ve been thinking a bit about the ramifications of the C++ vs. Python vs. Ruby benchmarking fud I wrote about in an earlier post
I’ve been looking at this from the point of view of how Ruby implements Arrays, digging deeply in to array.c, but I just stepped back and I noticed something which might or might not be important.
Besides using an Array rather than a linked list, the Baus Ruby benchmark doesn’t even do the same thing as the C++ one. In C++ the list is being used as a stack, items are added to the head of the list and removed from the head.
In the case of the Ruby benchmark, elements are inserted at the front of the Array using insert(0, obj), but removed using pop, which actually removes the last element. So instead of a stack we have a queue.
The Python code has a variation on the same problem, it uses append which adds to the end of the list, but del(0) which removes the first element.
Now I know that in benchmarking only performance matters, so I guess the old adage Make it work right before you make it work fast doesn’t necessarily apply.
Having said all that, another aspect of this is that the benchmarks take a rather naive approach in the use of the classes. For example, using Array#insert in Ruby is overkill for adding to the beginning or end of an array. More targeted methods such as push, unshift exist which are at least marginally faster because they have less cases to consider.
There’s no doubt that Ruby implementation technology needs to mature. Ruby is one of the most dynmic languages I’ve played with. Instance variable access is one area which is challenging, unlike in Smalltalk, where instance variables are declared and instance variable references can be bound to fixed offsets in compiled methods, Ruby instance variables are acquired dynamically and need more sophisticated run-time access. This is similar to the challenges which the designers of languages like Self posed for themselves and addressed, leading to impressive run-time performance achievements.
Subjectively, Ruby performance is remarkably good, but it can get better, and I’m sure that it will.
Trackbacks
Use the following link to trackback from your own site:
http://talklikeaduck.denhaven2.com/trackbacks?article_id=128





Here’s another attempt to speed up Ruby:
http://t-a-w.blogspot.com/2007/02/ruby-and-judy.html