Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map vs Object few vs many keys
Compares usage of Map vs object in two cases - many keys and few keys (< 30)
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/136.0.0.0 Safari/537.36 Edg/136.0.0.0
Browser:
Chrome 136
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Map lookup - large
6599.5 Ops/sec
Map lookup - small
8622.9 Ops/sec
Map lookup - tiny
8709.5 Ops/sec
Obj lookup - large
4425.2 Ops/sec
Obj lookup - small
9107.9 Ops/sec
Obj lookup - tiny
8133.3 Ops/sec
Script Preparation code:
const createKeyTestThings = n => { const keys = [] const map = new Map() const obj = {} const getConspicuousKey = seed => keys[Math.floor(seed * n)] for (let i = 0; i < n; i++) { const val = Math.random() const key = Math.random() keys.push(key) map.set(key, val) obj[key] = val } return { obj, map, getConspicuousKey } } const largeN = 16384, smallN = 100, tinyN = 15 const large = createKeyTestThings(largeN) const small = createKeyTestThings(smallN) const tiny = createKeyTestThings(tinyN)
Tests:
Map lookup - large
const { getConspicuousKey, map } = large for (let i=0; i<1000; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = map.get(key) }
Map lookup - small
const { getConspicuousKey, map } = small for (let i=0; i<1000; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = map.get(key) }
Map lookup - tiny
const { getConspicuousKey, map } = tiny for (let i=0; i<1000; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = map.get(key) }
Obj lookup - large
const { getConspicuousKey, obj } = large for (let i=0; i<1000; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = obj[key] }
Obj lookup - small
const { getConspicuousKey, obj } = small for (let i=0; i<1000; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = obj[key] }
Obj lookup - tiny
const { getConspicuousKey, obj } = tiny for (let i=0; i<1000; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = obj[key] }