Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
sorting
map & find with O(n^2) vs 2 iterations
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
map & find
248.9 Ops/sec
lookup map using obj
16009.8 Ops/sec
lookup map using map
14976.1 Ops/sec
Script Preparation code:
ids = [...Array(1000)].map(() => window.crypto.randomUUID()); shuffledData = ids.sort(() => 0.5 - Math.random()).map(id => ({id, value: window.crypto.randomUUID()}));
Tests:
map & find
const sortedData = ids.map(id => shuffledData.find(item => item.id === id));
lookup map using obj
const map = {}; shuffledData.forEach(item => map[item.id] = item); const sortedData = ids.map(id => map[id]);
lookup map using map
const map = new Map(); shuffledData.forEach(item => map.set(item.id, item)); const sortedData = ids.map(id => map.get(id));