Array vs sparce array loop

JavaScript performance comparison

Test case created by Fabio Costa

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var contiguousArray = [9,8,7,6,5,3,2,1,0,56,77,32,23,12,31,98];
    var sparceArray = [9,8,7,6,5,,,1,0,56,77,32,,12,,98];
    var obj = {9:1,8:1,7:1,6:1,5:1,1:1,0:1,56:1,77:1,32:1,12:1,98: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
Contiguous Array
for (var i = 0; i < contiguousArray.length;i++) {
  var x = contiguousArray[i];
}
 
pending…
Sparce Array
for (var i = 0; i < sparceArray.length;i++) {
  var x = sparceArray[i];
}
pending…
Object
for (var i in obj) {
  var x = obj[i];
}
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