Skip to content

Instantly share code, notes, and snippets.

@inkel
Created April 18, 2011 12:56
Show Gist options
  • Save inkel/925274 to your computer and use it in GitHub Desktop.
Save inkel/925274 to your computer and use it in GitHub Desktop.
fib(30) in Ruby & PHP
<?php
function fib($n) {
return ($n > 1) ? fib($n - 2) + fib($n - 1) : $n;
}
echo fib(30);
def fib n
if n > 1
fib(n - 2) + fib(n - 1)
else
n
end
end
puts fib(30)
$ time php fibo.php
832040
real 0m1.342s
user 0m1.320s
sys 0m0.000s
$ time ruby fibo.rb
832040
real 0m0.330s
user 0m0.320s
sys 0m0.010s
@inkel
Copy link
Author

inkel commented Apr 18, 2011

Stupid test I did at work to show a fellow programmer that Ruby is not as slow as it used to be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment