Test fibo array vs var

JavaScript performance comparison

Revision 3 of this test case created

Info

Test the speed of using array or 3 var to execute fibonaci

Preparation code

Test fibo
<script>
Benchmark.prototype.setup = function() {
    function fib(n){
      return n<2?n:fib(n-1)+fib(n-2);
    }
   
    function fiboVar(n)
    {
      var valeur = 1;
      var precedente = 0;
      var temp;
      for (var i = 0; i < n; i++) {
        temp = valeur;
        valeur += precedente;
        precedente = temp;
      }
    }
   
    function fiboArray(n)
    {
      aFibo = [0, 1];
      for (var i = 2; i <= n; i++)
      {
        aFibo[i] = aFibo[i - 1] + aFibo[i - 2];
      }
    }
   
};
</script>

Preparation code output

Test fibo

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Var
fiboVar(16);
pending…
Array
fiboArray(16);
 
pending…
recursive
fib(16);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment