Ruby Fibonacci Shootout
christopherroach.com
christopherroach.com
But, then again, it doesn't really matter. Is Ruby fast enough to work for most uses? Yes. If you really, really, really care about execution speed, would you use Ruby? I don't know. If you care that much about execution speed, you will probably do more benchmarks than I care to think of.
Apparently Firefox doesn't like the self-closing script tag?
object Main {
def fib(n : int) : int = {
if(n < 2) n
else
fib(n-1) + fib(n-2)
}
def main(args: Array[String]) = {
for (i <- 0 until 37) {
printf("n = " + i.toString + " => "+fib(i).toString)
}
}
}I don't know how you got 4 seconds unless you ran the program as a script and had a lot of other stuff running simultaneously. A simple scala hello world program on my machine has a startup time of 1.5 seconds when run as a script.