lookup (v4)

Revision 4 of this benchmark created on


Description

Array#indexOf vs Object property lookup

Preparation HTML

<script>
  var array = [],
      object = {},
      smallArray = [],
      smallObject = {},
      i;
  
  for (i = 0; i < 5000; i++) {
   array[i] = i;
   object[i] = i;
  }
  for (i = 0; i < 5000; i++) {
   smallArray[i] = i;
   smallObject[i] = i;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array#indexOf
array[array.indexOf(5000)] + array[array.indexOf(9999)] + array[array.indexOf(0)]
ready
Object property lookup
object['5000'] + object['9999'] + object['0']
ready
small Array#indexOf
smallArray[smallArray.indexOf(25)] + smallArray[smallArray.indexOf(49)] + smallArray[smallArray.indexOf(0)]
ready
small Object property lookup
smallObject['25'] + smallObject['49'] + smallObject['0']
ready

Revisions

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