Test fibo array vs var
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
Var |
|
pending… |
Array |
|
pending… |
recursive |
|
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:
- Revision 1: published by Jonathan Martel
- Revision 2: published
- Revision 3: published
0 comments