Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array.find vs. Map.get 2
Test the performance of Array.find vs. Map.get, with various array sizes, and with/without conversion from array to 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 Edg/131.0.0.0
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Array.find, 3elements
25565820.0 Ops/sec
Map.get, 3 elements
41586064.0 Ops/sec
Array.find, 10 elements
22213176.0 Ops/sec
Map.get, 10 elements
43002588.0 Ops/sec
Script Preparation code:
function getRandomElement(id) { return { id, a: Math.random(), b: Math.random(), c: Math.random(), } } function getArray(length) { const result = []; for (let i = 0; i < length; i++) { result.push(getRandomElement(i)) } return result; } function arrayToMap(array) { return new Map(array.map(el => [el.id, el])); } function getRandomInt(max) { return Math.floor(Math.random() * max); } array_small = getArray(3); array_large = getArray(10); map_small = arrayToMap(array_small); map_large = arrayToMap(array_large);
Tests:
Array.find, 3elements
const target = getRandomInt(2); array_small.find(el => el.id === target);
Map.get, 3 elements
const target = getRandomInt(2); map_small.get(target);
Array.find, 10 elements
const target = getRandomInt(9); array_large.find(el => el.id === target);
Map.get, 10 elements
const target = getRandomInt(9); map_large.get(target)