Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map string versus number keys (1000 entries)
tests the performance of string vs number keys in a 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/141.0.0.0 Safari/537.36 Edg/141.0.0.0
Browser:
Chrome 141
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
string map
5783.4 Ops/sec
int map
2723.7 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var intMap = new Map(); var stringMap = new Map(); // arrays of keys so they don't have to construct them in the test cases var stringKeys = []; var intKeys = []; for (let i = 0; i < 1000; i++) { // identical values var value = "test123" + i.toString() intMap.set(i, value); intKeys.push(i); stringMap.set(i.toString(), value); stringKeys.push(i.toString()); } function shuffle(array) { let currentIndex = array.length; // While there remain elements to shuffle... while (currentIndex != 0) { // Pick a remaining element... let randomIndex = Math.floor(Math.random() * currentIndex); currentIndex--; // And swap it with the current element. [array[currentIndex], array[randomIndex]] = [ array[randomIndex], array[currentIndex]]; } } // for the tests later var stringOutputValues = []; var intOutputValues = []; // shuffle the arrays so they don't benefit from any order advantages shuffle(stringKeys); shuffle(intKeys);
Tests:
string map
let i = 0; for (const stringKey of stringKeys) { // do (identical) work w/ the values so there's no optimisation. // adds [accessNum, value concat accessNum] to the stringOutputValues array stringOutputValues.push([i.toString(), stringMap.get(stringKey) + i.toString()]); i++; }
int map
let i = 0; for (const intKey of intKeys) { // do (identical) work w/ the values so there's no optimisation. // adds [accessNum, value concat accessNum] to the intOutputValues array intOutputValues.push([i.toString(), intMap.get(intKey) + i.toString()]); i++; }