Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map.get vs array.indexOf
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Browser:
Firefox 152
Operating system:
Windows
Device Platform:
Desktop
Date tested:
26 days ago
indexOf
1.2M/s
Map
1.1M/s
View exact numbers
Test name
Executions per second
✓
indexOf
1,182,777 Ops/sec
Map
1,134,638 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Tests:
Map
const order = ['a', 'b', 'c'] const orderMap = new Map(order.map((letter, index) => [letter, index])) const data = ['b', 'c', 'a', 'd'] data.sort((a, b) => (orderMap.get(a) ?? Infinity - orderMap.get(b) ?? Infinity))
indexOf
const order = ['a', 'b', 'c'] const data = ['b', 'c', 'a', 'd'] data.sort((a, b) => { const indexA = order?.indexOf(a) const indexB = order?.indexOf(b) if (indexA !== -1 && indexB !== -1) return indexA - indexB if (indexA === -1 && indexB !== -1) return 1 if (indexA !== -1 && indexB === -1) return -1 return 0 })