Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JUST Object.entries VS Object.keys VS Object.values
(version: 0)
Comparing performance of:
Object.entries vs Object.keys vs Object.values
Created:
2 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 < 10000; i++) { window.parentObj[makeid()] = makeid(); }
Tests:
Object.entries
Object.entries(window.parentObj)
Object.keys
Object.keys(window.parentObj)
Object.values
Object.values(window.parentObj)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object.entries
Object.keys
Object.values
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:120.0) Gecko/20100101 Firefox/120.0
Browser/OS:
Firefox 120 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.entries
1797.5 Ops/sec
Object.keys
7779.7 Ops/sec
Object.values
3061.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Overview** The test case, "JUST Object.entries VS Object.keys VS Object.values", compares the performance of three methods: `Object.entries()`, `Object.keys()`, and `Object.values()` on a specific JavaScript object. The benchmark is designed to measure which method is the fastest for iterating over an object's properties. **Benchmark Preparation Code** The preparation code creates a large JavaScript object, `window.parentObj`, with 10,000 properties where each property has a random key (a string of 5 characters) and a corresponding value. This object is created using a function called `makeid()`, which generates a random string of 5 characters. **Individual Test Cases** There are three individual test cases: 1. **`Object.entries(window.parentObj)`**: This method returns an array of [key, value] pairs from the specified object. 2. **`Object.keys(window.parentObj)`**: This method returns an array of keys (string values) from the specified object. 3. **`Object.values(window.parentObj)`**: This method returns an array of values (values associated with the key-value pairs) from the specified object. **Comparison** The benchmark compares the performance of these three methods by executing each one a large number of times and measuring how many executions per second are performed on a specific browser configuration (Firefox 120, running on a Mac OS X 10.15 desktop). **Options Compared** * `Object.entries()` vs `Object.keys()`: Both methods iterate over the object's properties, but `Object.entries()` returns an array of key-value pairs, while `Object.keys()` returns only an array of keys. * `Object.values()` vs `Object.keys()`: This is a comparison between two methods that return different types of data: values and keys. **Pros and Cons** * **`Object.entries()`**: + Pros: Returns an array of key-value pairs, which can be useful for iterating over objects with custom logic. + Cons: May have additional overhead due to creating an array of pairs. * **`Object.keys()`**: + Pros: Lightweight, efficient, and easy to use. + Cons: Only returns an array of keys, which may limit its usefulness in certain scenarios. * **`Object.values()`**: + Pros: Returns an array of values, which can be useful for iterating over objects with specific logic. + Cons: May have additional overhead due to creating an array of values. **Library** None. This benchmark only uses built-in JavaScript methods. **Special JS Feature/Syntax** No special features or syntax are used in this benchmark. It's focused on comparing the performance of three standard JavaScript methods. **Alternatives** * If you're looking for alternative methods to iterate over objects, consider using `for...in`, `forEach()`, or `reduce()`. * For specific use cases, you might prefer other libraries like Lodash or Ramda, which provide additional functions for working with objects and arrays.
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
Array of key values - Object.entries VS Object.keys
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?