2d-array vs. object

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var len = 1000;
    var string = "";
   
    var array1= new Array(len);
    for (var i = 0; i < len; i++) {
    array1[i] = new Array(len);
    }
   
    var array2 = new Array(len * len);
};
</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
two_dimensional
for (var x = 0; x < len; x++) {
for (var y = 0; y < len; y++) {
array1[x][y] = "lalalal";
}
}

for (var x = 0; x < len; x++) {
for (var y = 0; y < len; y++) {
string = array1[x][y];
}
}
 
pending…
string
for (var x = 0; x < len; x++) {
for (var y = 0; y < len; y++) {
array1[x + "-" + y] = "lalalal";
}
}

for (var x = 0; x < len; x++) {
for (var y = 0; y < len; y++) {
string = array1[x + "-" + y];
}
}
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