Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object values vs _.values dom andy
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Object values vs _.values
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
Tests:
Object values
const value = 10000 const findMe = value - 1; const numbers = {}; for (let i = 0; i < value; i++) { numbers[i] = i } Object.values(numbers);
_.values
const value = 10000 const findMe = value - 1; const numbers = {}; for (let i = 0; i < value; i++) { numbers[i] = i } _.values(numbers);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object values
_.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 dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is being tested?** The benchmark compares two approaches to iterate over the values of an object: using the spread operator (`Object.values`) and the traditional `concat` method with a `for...in` loop. The test case creates an array of 10,000 elements and then iterates over its values using both methods. **Options compared** The benchmark compares two options: 1. **`Object.values(numbers)`**: This uses the spread operator to create a new array containing the values of the object `numbers`. It's a concise and modern way to iterate over an object's properties. 2. **Traditional `concat` method with a `for...in` loop**: This uses a `for...in` loop to iterate over the object's properties, concatenating each value into a new array using the `concat` method. **Pros and cons of each approach** * **`Object.values(numbers)`**: + Pros: concise, modern syntax, efficient iteration. + Cons: may not be supported in older browsers or versions of JavaScript, can be slower for very large arrays due to the overhead of creating a new array. * **Traditional `concat` method with a `for...in` loop**: + Pros: widely supported across browsers and versions of JavaScript, can be faster for very large arrays since it avoids creating a new array. + Cons: less concise and modern syntax, may require more boilerplate code. **Library usage** The benchmark uses the Lodash library (`lodash.core.js`) to provide the `_.values` function, which is an alias for the spread operator. The use of Lodash provides a convenient way to iterate over objects without having to implement it manually. **Special JS feature or syntax** There are no special JavaScript features or syntax used in this benchmark beyond what's mentioned earlier (spread operator and traditional `concat` method). **Other alternatives** If you were to rewrite this benchmark, you could consider using other approaches, such as: * Using a library like `Array.prototype.forEach()` or `Array.prototype.forEachIndex()` instead of the spread operator. * Using a custom implementation of iteration over an object's properties. * Using a different data structure, such as an array with a length property and methods to access its elements. Keep in mind that these alternatives may affect the performance and readability of your benchmark, so it's essential to choose the approach that best suits your use case.
Related benchmarks:
Object values vs _.values
Object values vs _.values vs my-values
Array.prototype.concat vs spread operator vs lodash.concat - variable and constant
array find vs some vs lodash
Object values vs lodash _.values
Comments
Confirm delete:
Do you really want to delete benchmark?