Python vs Ruby

Yukihiro Matsumoto matz at zetabits.com
Sat Jan 27 09:44:30 EST 2001


Hi,

entropia <entropiamax at jazzfree.com> writes:

|Some time ago I tested Ruby vs Python:
|I made a program that calculates a fibonacci numbers.
|Python was as double as fast (Win95). Maybe that is because
|in Ruby a number is a class, in Python not.

double?  Fibonacci is mostly based on function calls so that
it's not the best field of Ruby.  But they give almost same
performance result on my box.

--- fib.py
# calculate Fibonacci(20)
# for benchmark
def fib(n):
  if n<2:
    return n
  else:
    return fib(n-2)+fib(n-1)

print fib(20)
---

--- fib.rb
# calculate Fibonacci(20)
# for benchmark
def fib(n)
  if n<2
    n
  else
    fib(n-2)+fib(n-1)
  end
end
print(fib(20), "\n");
---



More information about the Python-list mailing list