Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
For of vs Object.values
(version: 0)
Comparing performance of:
For of vs Object.values
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var list = []; var obj = {}; for(let i = 0; i < 1000; i += 1) { list.push(`entry_${i}`); obj[i] = `entry_${i}`; }
Tests:
For of
for(const key of list) { console.log(key); }
Object.values
Object.values(obj).forEach((value) => console.log(value));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
For of
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 benchmark and explain what's being tested. **What is being tested?** MeasureThat.net is testing two JavaScript microbenchmarks: a simple `for...of` loop and using `Object.values()` to iterate over an object. The test cases are designed to compare the performance of these two approaches in terms of execution speed. **Options compared:** * **For...of loop**: This is a newer iteration syntax in JavaScript that allows iterating over arrays or iterables without the need for explicit indexing. * **Object.values()**: This method returns an array-like object containing all the property values of the given object. It's often used when you need to access multiple properties at once. **Pros and Cons:** * **For...of loop**: + Pros: - Can be more readable, especially for simple iteration scenarios. - Eliminates the need for explicit indexing, making it easier to write code that iterates over an array or iterable without knowing its length beforehand. + Cons: - May incur a performance penalty compared to traditional `for` loops, especially when dealing with large datasets. * **Object.values()**: + Pros: - Provides a convenient way to access multiple properties at once, making it easier to work with objects in certain scenarios. + Cons: - Can be slower than traditional array iteration methods like `forEach()` or `for` loops, especially when dealing with large datasets. **Library and its purpose:** There is no specific library used in this benchmark. It only relies on the built-in JavaScript features mentioned above. **Special JS feature or syntax:** * **For...of loop**: This is a newer iteration syntax introduced in ECMAScript 2015 (ES6). It allows iterating over arrays, iterables, or maps without the need for explicit indexing. * **Object.values()**: This method was introduced in ECMAScript 2017 (ES7). **Other alternatives:** For iterating over an array, you could use traditional `for` loops with `index++`, or more modern methods like `forEach()` or `map()`. For accessing multiple properties at once, you might consider using object destructuring (`const { prop1, prop2 } = obj;`) or other spread operators (`[...obj.keys()].map(key => obj[key])`). In the context of this benchmark, the use of `Object.values()` is a good example of how to iterate over an object's properties in a concise and expressive way. However, depending on your specific use case, you might choose to use other methods for iterating or accessing data.
Related benchmarks:
obj vs array
For in vs For of
Object entries vs forin
For in vs Object.*.forEach vs Object.values vs _.forEach(_.values v3
For in vs Object.*.forEach vs Object.values 2
Comments
Confirm delete:
Do you really want to delete benchmark?