Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object iterat1on
(version: 0)
Comparing performance of:
Object.entries vs Object.keys vs Object.values
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
Object.entries
const myObj = {}; for (let i = 0; i < 1000; i += 1) { myObj[i] = {key: "value"}; } Object.entries(myObj).forEach(function([i, doc]) { const key = i; const value = doc.value; });
Object.keys
const myObj = {}; for (let i = 0; i < 1000; i += 1) { myObj[i] = {key: "value"}; } Object.keys(myObj).forEach(function(key) { const doc = myObj[key]; const value = doc.value; });
Object.values
const myObj = {}; for (let i = 0; i < 1000; i += 1) { myObj[i] = {key: "value"}; } Object.values(myObj).forEach(function(doc) { const value = doc.value; });
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:
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):
**What is tested on the provided JSON?** The provided JSON represents a set of microbenchmarks for JavaScript, specifically for iterating over objects using three different methods: `Object.keys()`, `Object.values()`, and `Object.entries()`. Each benchmark definition consists of a script that creates an object with 1000 properties, each containing a "key" property with the value "value". The script then uses one of the three iteration methods to iterate over the object's properties, extracting the key-value pairs. **Options compared** The three options being compared are: 1. `Object.keys()`: Iterates over an object's keys using the `keys()` method. 2. `Object.values()`: Iterates over an object's values using the `values()` method. 3. `Object.entries()`: Iterates over an object's key-value pairs using the `entries()` method. **Pros and Cons of each approach:** 1. **`Object.keys()`**: * Pros: Fast and lightweight, as it only iterates over keys without the overhead of values. * Cons: Requires additional lookup to access the value associated with each key. 2. **`Object.values()`**: * Pros: Iterates directly over values, avoiding unnecessary lookups for corresponding keys. * Cons: May be slower due to the need to create an intermediate array or use a callback function. 3. **`Object.entries()`**: * Pros: Provides both key and value in a single iteration, reducing the number of lookups required. * Cons: May be slower than `Object.keys()` due to the additional processing required for each entry. **Library usage** None of the benchmark definitions explicitly use any libraries. However, it's worth noting that some JavaScript engines, like V8 (used by Chrome), have built-in optimizations and features that might affect the performance of these benchmarks. **Special JS features or syntax** This benchmark does not require any special JavaScript features or syntax beyond standard ECMAScript. **Alternative approaches** Other ways to iterate over objects in JavaScript include: * Using a `for...in` loop, which iterates over both keys and values. * Using a `for...of` loop with an array-like object (not applicable here). * Using a custom iterator or generator function. These alternatives are not being compared in this benchmark.
Related benchmarks:
Javascript iterate object keys
Object iteration for-in vs object.keys
Iterating Through an Object with `forEach()`
for in / object.keys test
Comments
Confirm delete:
Do you really want to delete benchmark?