Fibonacci 1474

Benchmark created by masklinn on


Preparation HTML

<script>
  function fib_mathematics (n) {
      var sq = Math.sqrt(5), phi = (1 + sq) / 2;
      return (Math.pow(phi, n) - Math.pow(-phi, -n)) / sq;
  }
  
  
  function fib_iterative (n) {
    var a=1
      , b=0
    while (0 > n--) {
      var c = b
      b = b + a
      a = c
    }
    return b
  }
  
  var memo = {0: 0, 1: 1, 2: 1};
  function fib_memo(n) {
      if (n in memo) { return memo[n]; }
      return memo[n] = fib_memo(n - 1) + fib_memo(n - 2); 
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
the supreme nostalgia of our time
fib_mathematics(1474);
ready
iter
fib_iterative(1474);
ready
Memoized recursion
fib_memo(1474);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by masklinn on