Fibonacci Sequence

JavaScript performance comparison

Revision 2 of this test case created by

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
fibonacciLongest
function calculateFibonacciNumbers(max) {  
  var valOne
    , valTwo
    , valAdd
    , fibArr = [];

  for(var i = 1; i < max; i++){
    if(i === 1) {
      valOne = 0;
      valTwo = 1;
      fibArr.push(valOne, valTwo);
      continue;
    }
   
    valAdd = valOne + valTwo;
    valOne = valTwo;
    valTwo = valAdd;
    fibArr.push(valAdd);
  }
  return fibArr;
}

calculateFibonacciNumbers(1000);
pending…
fibonacciLong
function calculateFibonacciNumbers(max) {  
  var valOne = 0
    , valTwo = 1
    , fibNum
    , fibNums = [0, 1];

  for (var i = 2; i < max; i++) {
    fibNum = valOne + valTwo;
    valOne = valTwo;
    valTwo = fibNum;
    fibNums.push(fibNum);
  }
  return fibNums;
}

calculateFibonacciNumbers(1000);
pending…
fibonacciShort
function calculateFibonacciNumbers(max) {  
  var fib = [0, 1]
  for (var i = 2; i < max; i++ ) {
    fib.push( fib[i - 1] + fib[i - 2] )
  }
  return fib
}

calculateFibonacciNumbers(1000)
pending…

Compare results of other browsers

Revisions

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

0 Comments