Amidst all of the discussion about the alioth benchmarks and how they are 
(insert disparaging term here) there was a little discussion about the 
Ackermann benchmark and how Ruby finishes dead last even behind gawk(in 
fact doesn't finish for values of N larger than 6).

Here's the benchmark code:

  def ack(m, n)
    if m == 0 then
	n + 1
    elsif n == 0 then
	ack(m - 1, 1)
    else
	ack(m - 1, ack(m, n - 1))
    end
  end

  NUM = Integer(ARGV.shift || 1)
  print "Ack(3,", NUM, "): ", ack(3, NUM), "\n"


Well, that's simple enough.  Nothing to improve there and essentially 
looks like the Python version, except that the python version includes:

  import sys
  sys.setrecursionlimit(5000000)

....kind of handy that they can do that from within their program.


So the conclusion is that Ruby isn't so great at recursion (not a new 
conclusion).  If you're looking for a language that's good for recursion 
(because you like that style of programming or whatever) then looking at 
the results of this benchmark would be informative.  You could tell right 
away that Ruby isn't a good choice for that style of programming.  One 
might dismiss this by saying "well, I never use recursion anyway", but a 
lot of algorithms are much easier to implement recusively (algorithms 
which deal with walking trees for example).

That brings up the question: why is Ruby so bad at recursion?  
Is it possible to improve (and at what are the tradeoffs)?



Phil