fibonacci-js

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function fib(n){
      return n<2?n:fib(n-1)+fib(n-2);
    }
   
    function fib2(n) {
        if(n<2)
                return n;
        else
        {
                var result =[0,1,2];
                for (var i = 3; i <= n; i++) {
                        result[i] = result[i-2] + result[i-1];
                }
                return result[n-1];
        }
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
recursive
fib(20)
pending…
for loop
fib2(20)
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