Array.indexOf vs Object's "in operator (v21)

Revision 21 of this benchmark created on


Description

Testing if access through Array.indexOf or Object's in Operator is faster.

Setup

var arr = [
      'that',
      'is',
      'some',
      'nice',
      'some',
      'test',
      'here',
      'they',
      'will',
      'not',
      'be',
      'found',
      'anywhere',
      'else'
    ]
    
    var obj = {
      'that': null,
      'is': null,
      'some': null,
      'nice': null,
      'test': null,
      'here': null,
      'they': null,
      'will': null,
      'not': null,
      'be': null,
      'found': null,
      'anywhere': null,
      'else': null
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array - Find first element
arr.indexOf('that');
ready
Object - Find first element
'that' in obj;
ready
Array - Find last element
arr.indexOf('else');
ready
Object - Find last element
'else' in obj;
ready

Revisions

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