Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
numeric vs string property accessor
compare setting and getting values of property accessed via numeric key and string key
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/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
numeric keys
109722.3 Ops/sec
string keys
35273.4 Ops/sec
string keys, with key caching
48385.3 Ops/sec
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ async function globalMeasureThatScriptPrepareFunction() { // This function is optional, feel free to remove it. // await someThing(); }
Tests:
numeric keys
let o = {}; // write for (let n=1; n <= 1000; n++) { if (o[n] === undefined) o[n] = n; } // read let sum = 0; for (let n=1; n <= 1000; n++) { if (o[n] !== undefined) sum += o[n]; } //console.log("numeric keys - sum ", sum); // expects 500500 (1 - 1000)
string keys
let o = {}; // write for (let n=1; n <= 1000; n++) { if (o[n.toString()] === undefined) o[n.toString()] = n; } // read let sum = 0; for (let n=1; n <= 1000; n++) { if (o[n.toString()] !== undefined) sum += o[n.toString()]; } //console.log("string keys - sum ", sum); // expects 500500 (1 - 1000)
string keys, with key caching (n.toString())
let o = {}; let k; // write for (let n=1; n <= 1000; n++) { k = n.toString(); if (o[k] === undefined) o[k] = n; } // read let sum = 0; for (let n=1; n <= 1000; n++) { k = n.toString(); if (o[k] !== undefined) sum += o[k]; } //console.log("string keys - sum ", sum); // expects 500500 (1 - 1000)
string keys, with key caching ("" + n)
let o = {}; let k; // write for (let n=1; n <= 1000; n++) { k = "" + n; if (o[k] === undefined) o[k] = n; } // read let sum = 0; for (let n=1; n <= 1000; n++) { k = "" + n; if (o[k] !== undefined) sum += o[k]; } //console.log("string keys - sum ", sum); // expects 500500 (1 - 1000)