Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object entries, values, keys perf
(version: 0)
Comparing performance of:
entries vs Values vs Keys
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } window.obj = {}; for (let i = 0; i < 100; i++) { window.obj[makeid()] = makeid(); }
Tests:
entries
const len = Object.entries(window.obj).length;
Values
const len = Object.values(window.obj).length;
Keys
const len = Object.keys(window.obj).length;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
entries
Values
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):
I'll break down the provided benchmark and explain what's being tested, compared options, their pros and cons, and other considerations. **Benchmark Definition JSON** The benchmark definition represents three test cases: 1. `Object.entries(window.obj).length` 2. `Object.values(window.obj).length` 3. `Object.keys(window.obj).length` These test cases aim to measure the performance of different methods for getting the number of entries, values, and keys in an object. **Script Preparation Code** The script preparation code generates a random object (`window.obj`) with 100 key-value pairs. The object is created using a function `makeid()` that generates a random string. **Html Preparation Code** There is no HTML preparation code provided, which means the benchmark will be executed in a headless browser (likely Chrome). **Comparison of Options** The three test cases are comparing different methods for getting the number of entries, values, and keys in an object: 1. `Object.entries(window.obj).length` 2. `Object.values(window.obj).length` 3. `Object.keys(window.obj).length` Here's a brief overview of each method: * `Object.entries()`: Returns an array of key-value pairs in the object. The length property returns the number of entries. * `Object.values()`: Returns an array of values in the object. The length property returns the number of values. * `Object.keys()`: Returns an array of keys in the object. The length property returns the number of keys. **Pros and Cons** Here's a brief summary of each method: 1. `Object.entries()`: * Pros: Efficient and reliable way to get all key-value pairs. * Cons: May be slower than other methods if the object is very large, as it needs to create an array of entries. 2. `Object.values()`: * Pros: Faster than `Object.keys()` for large objects, as it doesn't need to create an array of keys. * Cons: Only returns values, not key-value pairs. 3. `Object.keys()`: * Pros: Fast and efficient way to get the number of keys. * Cons: May be slower than `Object.entries()` if the object is very large, as it needs to create an array of keys. **Library and Special JS Features** There are no specific libraries or special JS features mentioned in the benchmark definition. However, using modern JavaScript features like arrow functions (`() => {}`) is not explicitly forbidden, but they might be ignored by older browsers. **Other Considerations** * **Browser and device platform**: The benchmark results show that different browsers (Chrome 94) on desktop platforms produce varying execution times. * **Cache and persistence**: There's no indication of cache or persistence issues in the benchmark definition. However, in a real-world scenario, this might be an important consideration. * **Garbage collection**: The benchmark might not account for the impact of garbage collection on performance. **Alternatives** Other alternatives to measure object property access performance could include: * Using `Array.prototype.forEach()` or `Array.prototype.map()` instead of `Object.entries()` * Using `Array.prototype.reduce()` instead of `Object.values()` * Using `String.prototype.split()` or `String.prototype.indexOf()` instead of `Object.keys()` Keep in mind that these alternatives might not provide identical results, and the best approach would depend on the specific use case and requirements.
Related benchmarks:
IE11 Object.entries
Object values: Object.entries VS Object.keys VS Object.keys with extra array VS Object.entries without array VS Object values: Object.entries loop for
Object values: Object.entries VS Object.keys VS Object.keys with extra array VS Object.entries without array VS for .. of
Object.entries VS Object.keys VS Object.keys with extra array VS Object.entries without array VS Array
Object.entries VS Object.keys VS Object.keys with extra array VS Object.entries without array VS Object.keys as separate array with for loop
Comments
Confirm delete:
Do you really want to delete benchmark?