Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.values vs Object.values
(version: 0)
Comparing performance of:
lodash.values vs native
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var value = {a: 30310, b: 100303, c: 3040494};
Tests:
lodash.values
_.values(value)
native
Object.values(value)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash.values
native
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 benchmark being tested. **Benchmark Description** The benchmark is comparing the performance of two approaches to get an array of values from an object: `_.values` (from the Lodash library) and `Object.values` (a built-in JavaScript method). **Options Compared** * `_.values`: This function takes an object as input and returns a new array containing all the property values in the same order. It uses the `for...in` loop to iterate over the object's properties, which has a performance impact. * `Object.values`: This is a built-in JavaScript method that returns an array of a given object's own enumerable property values. **Pros and Cons** * **_.values**: Pros: + Has been widely used for years, so many developers are familiar with it. + Can be useful when you need to preserve the original order of properties. Cons: + Uses `for...in` loop, which can lead to slower performance compared to other methods. * **Object.values**: Pros: + Is a built-in method, which means it's optimized for performance and stability. + Does not use loops or recursion, making it faster than _.values. Cons: + Might require more modern browsers or Node.js versions to work. **Library (Lodash)** Lodash is a popular JavaScript library that provides a wide range of utility functions. The `_.values` function is one of its many offerings, providing a convenient way to extract values from objects. In this benchmark, Lodash is used as part of the test script preparation code. **JavaScript Feature/Syntax (None)** There are no special JavaScript features or syntax being tested in this benchmark. It's purely about comparing the performance of two different approaches. **Other Alternatives** * For other methods to get an array of values from an object, you can use: + `Object.keys()`, `Array.prototype.map()` and `Array.prototype.reduce()`: This approach involves creating a new array by mapping over the keys of the object and then extracting the corresponding values. + `for...in` loop without using the spread operator or `map()`: If you want to avoid using built-in methods, you can use a simple `for...in` loop to iterate over the object's properties. Here is an example of how you might rewrite the benchmark script using these alternatives: ```javascript // Using Object.keys(), Array.prototype.map(), and Array.prototype.reduce() const values = {}; Object.keys(value).forEach(key => { values[key] = value[key]; }); console.log(values); // Using for...in loop without spread operator or map() const values2 = {}; for (const key in value) { if (value.hasOwnProperty(key)) { values2[key] = value[key]; } } console.log(values2); ```
Related benchmarks:
lodash.keys vs Object.keys
lodash.keys vs Object.keys
Lodash values vs Object.values
Get values from object
Comments
Confirm delete:
Do you really want to delete benchmark?