Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map string versus number keys (1000 entries)
(version: 1)
tests the performance of string vs number keys in a map
Comparing performance of:
string map vs int map
Created:
7 months ago
by:
Guest
Jump to the latest result
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++; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
string map
int map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Android 15; Mobile; rv:147.0) Gecko/147.0 Firefox/147.0
Browser/OS:
Firefox Mobile 147 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
string map
2705.3 Ops/sec
int map
2655.5 Ops/sec
Related benchmarks:
Map vs Object vs Reduce
Map vs Object Improved
Map string versus number keys
Map string versus number keys big sets
Map vs Object - Multiple keys
Map vs Object - Dynamic keys
Map vs Object read performance for a 1000 key lookup
Map.has vs Object hasOwnProperty vs direct check v2
int vs str map key perf set and get 1
Comments
Confirm delete:
Do you really want to delete benchmark?