How to calculate the Fibonacci Sequence in 10 different programming languages?

Which is fast?

Richard
Code Canteen

--

The Fibonacci Sequence is the series of numbers:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …

  • The first two is 0 and 1
  • The next number is found by adding up the two numbers before it.

If we use defined a function which was called fib , and n is the index of the sequence, then we can get this rule:

fib(0) --> 0
fib(1) --> 1
fib(n) --> fib(n-1) + fib(n-2)

This is a classic programming problem, so let’s implement the Fibonacci function in different programming languages and test which programming language is the fastest.

JavaScript

Code:

Result:

--

--