indexOf vs hash (v4)

Revision 4 of this benchmark created on


Setup

var a = ['barfoo', 'foobar', 'adameve', 'eveadam', 'baradam'];
    var hash = {};
    var set = new Set();
    a.forEach(function(prop) {
      hash[prop] = true;
      set.add(prop);
    });

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
a.indexOf('adameve');
ready
hash
hash['adameve']
ready
indeOf - first element on the array
a.indexOf('barfoo');
ready
hash - first element on the array
hash['barfoo'];
ready
indeOf - last element on the array
a.indexOf('baradam');
ready
hash - last element on the array
hash['baradam'];
ready
indexOf - not in array
a.indexOf('notinside')
ready
hash - not in array
hash['notinside']
ready
set
set.has('adameve')
ready
set - first element
set.has('barfoo')
ready
set - last element
set.has('baradam')
ready
set - not in list
set.has('notinside')
ready

Revisions

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