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
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 ?