Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Performance of object properties in relation with their length
(version: 0)
Does the length of an objects properties matter when doing lookups at scale?
Comparing performance of:
Very short keys vs Short keys vs Medium keys vs Long keys vs Very long keys
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function uuid() { // Public Domain/MIT var d = new Date().getTime(); //Timestamp var d2 = (typeof performance !== "undefined" && performance.now && performance.now() * 1000) || 0; //Time in microseconds since page-load or 0 if unsupported return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { var r = Math.random() * 16; //random number between 0 and 16 if (d > 0) { //Use timestamp until depleted r = (d + r) % 16 | 0; d = Math.floor(d / 16); } else { //Use microseconds since page-load if supported r = (d2 + r) % 16 | 0; d2 = Math.floor(d2 / 16); } return (c === "x" ? r : (r & 0x3) | 0x8).toString(16); }); } function shortId() { // I generate the UID from two parts here // to ensure the random number provide enough bits. let firstPart = (Math.random() * 46656) | 0; let secondPart = (Math.random() * 46656) | 0; firstPart = ("000" + firstPart.toString(36)).slice(-3); secondPart = ("000" + secondPart.toString(36)).slice(-3); return firstPart + secondPart; } function shuffle(array) { let currentIndex = array.length, randomIndex; // While there remain elements to shuffle. while (currentIndex != 0) { // Pick a remaining element. randomIndex = Math.floor(Math.random() * currentIndex); currentIndex--; // And swap it with the current element. [array[currentIndex], array[randomIndex]] = [ array[randomIndex], array[currentIndex], ]; } return array; } const NB_ITEMS = 100000; var objectWithVeryShortKeys = {}; var veryShortKeys = []; for (let i = 0; i < NB_ITEMS; i++) { let key = shortId(); objectWithVeryShortKeys[key] = Math.random(); veryShortKeys.push(key); } var objectWithShortKeys = {}; var shortKeys = []; for (let i = 0; i < NB_ITEMS; i++) { let key = uuid(); objectWithShortKeys[key] = Math.random(); shortKeys.push(key); } var objectWithMediumKeys = {}; var mediumKeys = []; for (let i = 0; i < NB_ITEMS; i++) { let key = `${uuid()}::${uuid()}`; objectWithMediumKeys[key] = Math.random(); mediumKeys.push(key); } var objectWithLongKeys = {}; var longKeys = []; for (let i = 0; i < NB_ITEMS; i++) { let key = `${uuid()}::${uuid()}::some_more_text::${uuid()}`; objectWithLongKeys[key] = Math.random(); longKeys.push(key); } var objectWithVeryLongKeys = {}; var veryLongKeys = []; for (let i = 0; i < NB_ITEMS; i++) { let key = `${uuid()}::${uuid()}::some_more_text::${uuid()}::${uuid()}::${uuid()}::some_more_text::${uuid()}`; objectWithVeryLongKeys[key] = Math.random(); veryLongKeys.push(key); } shuffle(veryShortKeys); shuffle(shortKeys); shuffle(mediumKeys); shuffle(longKeys); shuffle(veryLongKeys);
Tests:
Very short keys
let str = ""; for (let i = 0; i < 10000; i++) { str += objectWithVeryShortKeys[veryShortKeys[i]]; }
Short keys
let shortKeysStr = ""; for (let i = 0; i < 10000; i++) { shortKeysStr += objectWithShortKeys[shortKeys[i]]; }
Medium keys
let mediumKeysStr = ""; for (let i = 0; i < 10000; i++) { mediumKeysStr += objectWithMediumKeys[mediumKeys[i]]; }
Long keys
let longKeysStr = ""; for (let i = 0; i < 10000; i++) { longKeysStr += objectWithLongKeys[longKeys[i]]; }
Very long keys
let veryLongKeysStr = ""; for (let i = 0; i < 10000; i++) { veryLongKeysStr += objectWithVeryLongKeys[veryLongKeys[i]]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Very short keys
Short keys
Medium keys
Long keys
Very long keys
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Based on the provided code snippets and benchmark results, I'll attempt to answer your question. It appears that you're comparing the performance of different key length benchmarks using Firefox 111 on a Mac OS X 10.13 device. The benchmark definitions are as follows: 1. **Very short keys**: A loop that concatenates `objectWithVeryShortKeys[veryShortKeys[i]]` 10,000 times. 2. **Short keys**: A loop that concatenates `objectWithShortKeys[shortKeys[i]]` 10,000 times. 3. **Medium keys**: A loop that concatenates `objectWithMediumKeys[mediumKeys[i]]` 10,000 times. 4. **Long keys**: A loop that concatenates `objectWithLongKeys[longKeys[i]]` 10,000 times. 5. **Very long keys**: A loop that concatenates `objectWithVeryLongKeys[veryLongKeys[i]]` 10,000 times. The benchmark results show the following order of performance (fastest to slowest): 1. **Long keys** (ExecutionsPerSecond: 198.8664093017578) 2. **Medium keys** (ExecutionsPerSecond: 115.38461303710938) 3. **Very short keys** (ExecutionsPerSecond: 69.60873413085938) 4. **Short keys** (ExecutionsPerSecond: 62.35241344467778) 5. **Very long keys** (ExecutionsPerSecond: 212.64642333984375) Note that the execution times are relatively close, indicating that the difference in performance is not dramatic. Without more context or information about the specific use case or requirements of these benchmarks, it's difficult to provide a definitive answer. However, based on the provided data, **Long keys** seem to be the fastest, followed closely by **Very long keys**, suggesting that shorter key lengths result in better performance.
Related benchmarks:
Data Properties vs. Accessor Properties vs. Getter / Setter Methods
Data Properties vs. Accessor Properties vs. Getter / Setter Methods 1
Data Properties vs. Accessor Properties vs. Getter / Setter Methods 2
Empty an object in JavaScript (with baseline)
"this" property vs. closure upvalue
Comments
Confirm delete:
Do you really want to delete benchmark?