Array Lookup vs Object Lookup

Benchmark created on


Preparation HTML

<script>

var arr = [];
for (var i = 0; i < 10000; i++) {
  arr.push(10000 - i);
}

var obj = {};
for (var j = 0; j < 10000; j++) {
  obj[j] = 10000 - j;
}

</script>

Setup

var x = 0;
    var y = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Object access
for (var i = 0; i < 10000; i++) {
  x = obj[i];
}
ready
Array access
for (var j = 0; j < 10000; j++) {
  y = arr[j];
}
ready

Revisions

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