Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.keys() vs Object.values() vs Object.entries()
(version: 0)
Comparing performance of:
Object.keys() vs Object.values() vs Object.entries()
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script> const arr = [1,2,3,4,5] </script>
Tests:
Object.keys()
Object.keys(arr)
Object.values()
Object.values(arr)
Object.entries()
Object.entries(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object.keys()
Object.values()
Object.entries()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.keys()
30290832.0 Ops/sec
Object.values()
34233612.0 Ops/sec
Object.entries()
5809075.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark measures the performance of three different methods in JavaScript: `Object.keys()`, `Object.values()`, and `Object.entries()`. These methods are used to extract properties from an object. Specifically, they return: * `Object.keys(arr)`: An array of property names (strings) that can be accessed by using the bracket notation (`arr['property']`). * `Object.values(arr)`: An array of property values (values of type `x` where `x` is a primitive value such as number, string, boolean, etc.). * `Object.entries(arr)`: An array of key-value pairs, where each pair consists of the key and its corresponding value. **Options Compared** The benchmark compares the execution times of these three methods on an input array (`arr`). This comparison is useful to determine which method is most efficient for a particular use case. **Pros and Cons** Here's a brief overview of the pros and cons of each approach: 1. **Object.keys()** * Pros: * Fastest execution time (on average) since it only iterates over property names. * Low memory usage, as it doesn't create any new arrays or objects. * Cons: * May not be suitable for iterating over the actual values of the properties. 2. **Object.values()** * Pros: * Suitable for iterating over the actual values of the properties. * Can be useful when you need to access property values directly, such as in data processing or manipulation tasks. * Cons: * May have higher execution times than `Object.keys()` due to additional operations (e.g., array indexing and slicing). * Higher memory usage compared to `Object.keys()`, since it creates a new array. 3. **Object.entries()** * Pros: * Suitable for both iterating over key-value pairs and accessing property values directly. * Can be useful when working with objects that need to be processed as key-value pairs (e.g., JSON data). * Cons: * May have higher execution times than `Object.keys()` due to additional operations (e.g., array indexing and slicing). * Higher memory usage compared to `Object.keys()`, since it creates a new array. **Library or Special JS Feature** There is no specific library used in this benchmark. However, it's worth noting that the performance of these methods can be influenced by various factors, such as: * The type and size of the input data. * The engine or browser being used (e.g., V8 for Chrome). * Any additional plugins or extensions enabled. **Special JS Feature** There are no specific JavaScript features mentioned in this benchmark. However, it's always worth noting that newer versions of JavaScript engines may have introduced optimizations or changes to these methods that could affect their performance.
Related benchmarks:
Object.keys vs Object.values
key in object vs object.key
Object.keys vs Object.entries vs Object.values
Array.Prototype.at vs index
Comments
Confirm delete:
Do you really want to delete benchmark?