Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.entries VS Object.values Perf
(version: 0)
Comparing performance of:
Object.entries vs Object.values
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.parentObj = {}; for (let i = 0; i < 100; i++) { window.parentObj[makeid()] = makeid(); }
Tests:
Object.entries
const uniqNodes = new Set(); Object.entries(window.parentObj).forEach(([_identifier, node]) => { if (!uniqNodes.has(node)) { uniqNodes.add(node); } });
Object.values
const uniqNodes = new Set(); Object.values(window.parentObj).forEach((node) => { if (!uniqNodes.has(node)) { uniqNodes.add(node); } });
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:
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):
Let's break down the provided JSON data and explain what is being tested. **Benchmark Definition** The benchmark definition json provides two scripts that will be compared in terms of performance: `Object.entries` and `Object.values`. These methods are used to iterate over the properties (key-value pairs) or values, respectively, of an object. * **Object.entries**: This method returns an array of a given object's key-value pairs. The callback function receives two arguments: the key (`identifier`) and the value (`node`). * **Object.values**: This method returns an array containing all the values (i.e., the second element in each key-value pair) of an object. **Comparison Options** The benchmark compares the performance of these two methods. The options being compared are: 1. Using `Object.entries` with a `Set`. 2. Using `Object.values` with a `Set`. **Pros and Cons** * **Using Object.entries with a Set:** * **Pros:** It avoids iterating over the object's properties unnecessarily, as it only processes unique nodes. * **Cons:** The callback function receives two arguments (key and value), which might be less readable or efficient for some use cases. * **Using Object.values with a Set:** * **Pros:** It allows direct access to values without needing to destructure key-value pairs, making the code more concise. * **Cons:** It iterates over all properties (keys) in the object, which might be unnecessary if only unique values are needed. **Library** In both test cases, a `Set` is used. A `Set` is a collection of unique values that can be used to store and retrieve specific data efficiently. In this context, it's used to keep track of unique nodes in the object. **Special JS Feature/Syntax** There are no special JavaScript features or syntax being tested in these benchmark definitions. **Other Alternatives** If you were to compare other approaches for iterating over objects, some alternatives could be: * Using `for...in` and checking if the property exists in a separate array. * Using `Object.keys()` and accessing each key individually using bracket notation (`obj[key]`). * Creating an object with specific keys and then iterating over it. Keep in mind that these alternatives might have different performance characteristics depending on the use case.
Related benchmarks:
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.key vs Object.value vs Object.entries
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.values
Object entry counting: Object.entries VS Object.keys VS Object.values
Comments
Confirm delete:
Do you really want to delete benchmark?