Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
indexOf vs map vs Set vs native Map
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
indexOf
2914.0 Ops/sec
map
8589416.0 Ops/sec
set
9664027.0 Ops/sec
map2
10097610.0 Ops/sec
Script Preparation code:
var array = []; for (var i=0; i<3000; ++i) { array.push('00' + i); } function hasWithIndexOf(needle) { return array.indexOf(needle) !== -1; } var map = {}; array.forEach(item => map[item] = true); function hasWithMap(needle) { return needle in map; } var set = new Set(array); function hasWithSet(needle) { return set.has(needle); } var map2 = new Map(array.map(item => [item, true])); function hasWithMap2(needle) { return map2.has(needle); }
Tests:
indexOf
for (var i=0; i<100; ++i) { hasWithIndexOf('404'); }
map
for (var i=0; i<100; ++i) { hasWithMap('404'); }
set
for (var i=0; i<100; ++i) { hasWithSet('404'); }
map2
for (var i=0; i<100; ++i) { hasWithMap2('404'); }