Created
December 27, 2017 09:34
-
-
Save MicTech/f11a45b979254b4dd1e5eec85943acfb to your computer and use it in GitHub Desktop.
Fibonacci number benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fibonacci(40) takes 2 seconds in Node.js 0.6.14 | |
// http://en.wikipedia.org/wiki/Fibonacci_number | |
function fibonacci(n) { | |
return n < 2 ? n : fibonacci(n-2) + fibonacci(n-1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fibonacci(40) takes 60 seconds in PHP 5.4.0 | |
// fibonacci(40) takes 21 seconds in PHP 7 | |
function fibonacci($n) { | |
return $n < 2 ? $n : fibonacci($n-2) + fibonacci($n-1); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fibonacci(40) takes 42 seconds in Python 3.2.2 | |
def fibonacci(n): | |
return n if n < 2 else fibonacci(n-1) + fibonacci(n-2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fibonacci(40) takes 18 seconds in Ruby 1.9.3 | |
def fibonacci(n) | |
n < 2 ? n : fibonacci(n-1) + fibonacci(n-2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment