Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map lookup vs array index lookup
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Map lookup
956.7 Ops/sec
Array lookup
27027.3 Ops/sec
Script Preparation code:
var map = new Map(); var arrLookup = []; var items = []; for (var i = 0; i < 100; i++) { items[i] = []; for (var j = 0; j < 100; j++) { items[i][j] = [i,j]; if (Math.random() < 0.1) { map.set(i+","+j, Math.random()>=0.5); if (!arrLookup[i]) arrLookup[i] = []; arrLookup[i][j] = Math.random()>=0.5; } } }
Tests:
Map lookup
var results = [], i, j; for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { if (map.has(items[i][j] +"")) results.push(map.get(items[i][j]+"")); } } if (results.length === 0) throw Error();
Array lookup
var results = [], i, j; for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { if (arrLookup[i] && typeof arrLookup[i][j] !== "undefined") results.push(arrLookup[i][j]); } } if (results.length === 0) throw Error();