Fibonacci battle : typed vs normal arrays

JavaScript performance comparison

Test case created by Nicolas Froidure

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var normalSuit = [],
        typedSuit = new Uint32Array(45);
};
</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
Normal arrays
var n = 2, // rank
    suit = [0, 1]; // suit
while (n < 45) {
  suit[n] = suit[n - 1] + suit[n - 2];
  n++;
}
pending…
Typed arrays
var n = 2, // rank
    suit = new Uint32Array(45); // result
suit[0] = 0;
suit[1] = 1;
while (n < 45) {
  suit[n] = suit[n - 1] + suit[n - 2];
  n++;
}
pending…
Normal arrays (reused)
var n = 2; // rank
normalSuit[0]=0;
normalSuit[1]=1;
while (n < 45) {
  normalSuit[n] = normalSuit[n - 1] + normalSuit[n - 2];
  n++;
}
pending…
Typed arrays (reused)
var n = 2; // rank
typedSuit[0] = 0;
typedSuit[1] = 1;
while (n < 45) {
  typedSuit[n] = typedSuit[n - 1] + typedSuit[n - 2];
  n++;
}
pending…

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

Compare results of other browsers

0 comments

Add a comment