Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.entries vs Object.values basic
(version: 0)
Comparing performance of:
Object.entries vs Object.values
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = new Object() var keys = (new Array(10000)).fill(0).map((x, i) => { return i + 1 }) keys.forEach((x) => { obj['prop' + x] = x })
Tests:
Object.entries
Object.entries(obj);
Object.values
Object.values(obj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.entries
Object.values
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser/OS:
Firefox 141 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.entries
9128.2 Ops/sec
Object.values
47045.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is being tested?** The benchmark compares the performance of two methods: `Object.entries()` and `Object.values()`. The test case creates an object with 10,000 properties (keys) using a script preparation code. The resulting object is then used to measure the execution time of both methods. **Options compared:** There are two options being compared: 1. **Object.entries(obj)**: This method returns an array of tuples containing the keys and values of the object. 2. **Object.values(obj)**: This method returns an array containing the values of the object. **Pros and Cons of each approach:** * `Object.entries(obj)`: This approach has a slight overhead due to the creation of arrays, which can lead to slower performance compared to accessing individual property names directly. However, it provides a more flexible way to iterate over both keys and values simultaneously. * **Object.values(obj)**: This approach accesses individual property names using bracket notation (`obj['propX']`), which can be slower than the array-based approach. **Library usage:** There is no library explicitly mentioned in the benchmark definition. However, it's worth noting that `Object.entries()` and `Object.values()` are built-in JavaScript methods that don't rely on external libraries for their functionality. **Special JS features or syntax:** None of the provided test cases use special JavaScript features or syntax beyond the standard method definitions (`Object.entries()` and `Object.values()`). **Other alternatives:** If you were to write your own benchmarking script, some alternative approaches could be: * Accessing individual property names using bracket notation (`obj['propX']`) * Using a library like Lodash (`_.values(obj)` or `_keys(obj)`) for more concise and expressive code * Using a different data structure, such as an array of objects, to compare performance Keep in mind that these alternatives would likely require significant changes to the benchmark definition and script preparation code. **Benchmark preparation code:** The provided script preparation code creates an object with 10,000 properties using: ```javascript var obj = new Object(); var keys = (new Array(10000)).fill(0).map((x, i) => { return i + 1 }); keys.forEach((x) => { obj['prop' + x] = x }); ``` This code uses a combination of `Array.prototype.fill()` and `Array.prototype.map()` to create an array of 10,000 numbers. The resulting array is then used to populate the object with property names. **Individual test cases:** The provided benchmark definition includes two individual test cases: * `Object.entries(obj);` * `Object.values(obj);` These test cases measure the execution time of both methods on the same object with 10,000 properties.
Related benchmarks:
For in vs Object.keys.forEach FixedForYaRetard
Some benchmark
For in vs Object.*.forEach vs Object.values vs _.forEach(_.values v3
For in vs Object.*.forEach vs Object.values vs _.forEach(_.values vs n=arr.length
Comments
Confirm delete:
Do you really want to delete benchmark?