Object vs Array Access

Benchmark created on


Description

Just how slow is accessing objects compared to arrays?

Preparation HTML

<script>
  var arr = [],
      obj = {};
  
  for (var i = 0; i < 10000; i++) {
   arr.push(10000 - i);
   obj['name' + i] = 10000 - i;
  }
  
  var thisValue = 0;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array Access
for (var ia = 0; ia < 10000; ia++) {

 thisValue = arr[ia];

}
ready
Object Access
for (var io = 0; io < 10000; io++) {

 thisValue = obj['name' + io];

}
ready
Array Access Start
thisValue = arr[0];
ready
Array Access End
thisValue = arr[9999];
ready
Object Access Start
thisValue = obj.name0;
ready
Object Access End
thisValue = obj.name9999;
ready

Revisions

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