Object vs Array Access (v2)

Revision 2 of this 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[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[io];

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

Revisions

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