Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object values vs _.values
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Object values vs _.values
Created:
8 years ago
by:
Registered User
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
var a = { a: 1, b: 2, c: 3}; Object.values(a);
_.values
var a = { a: 1, b: 2, c: 3}; _.values(a);
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:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object values
8708972.0 Ops/sec
_.values
8288285.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided JSON. The benchmark is comparing two approaches to extract values from an object: 1. **Object.values()**: This is a built-in JavaScript method introduced in ES6 (EcmaScript 2015). It returns an array containing all the property values of an object. 2. **_.values()**: This is a function from the Lodash library, a popular utility library for functional programming in JavaScript. The `_.values()` function does essentially the same thing as `Object.values()`, but it's not part of the native JavaScript API. **Comparison Options:** The benchmark is comparing these two approaches: * **Native JavaScript (Object.values())**: This approach uses the built-in method from the JavaScript language. * **Lodash library (.values())**: This approach uses a function from an external library, which provides additional functionality and features beyond what's available in native JavaScript. **Pros and Cons:** ### Native JavaScript (Object.values()) Pros: * Fast: Using a native method can be faster since it doesn't require an additional function call or import. * Easy to understand: The syntax is straightforward and easy to read. Cons: * Limited functionality: `Object.values()` only works with objects, whereas other methods might work with arrays or other data structures. * Dependent on JavaScript version: The method was introduced in ES6, so it may not be supported in older browsers or environments that don't support this feature. ### Lodash library (.values()) Pros: * Wider compatibility: Since Lodash is a widely used utility library, _.values() is likely to work in more environments and browsers. * Additional features: Lodash provides many other useful functions for data manipulation and transformation. Cons: * Slower: Using an external function might introduce some overhead compared to native JavaScript methods. * Dependence on another library: If the test environment doesn't include Lodash, this approach will fail or behave unexpectedly. **Considerations:** * Performance-critical code should likely use native JavaScript methods whenever possible, as they tend to be faster and more efficient. * However, when working with a wide range of environments or older browsers that don't support certain features, using an external library like Lodash can provide necessary compatibility. Now, let's examine the individual test cases: In the first test case, `Object.values(a)`, we're creating an object `a` and calling the native JavaScript method to extract its values. In the second test case, `_.values(a)`, we're doing the same thing, but using the Lodash library function. The latest benchmark result shows that both approaches are reasonably fast, with Chrome 120 performing slightly better on the first test case (`Object.values(a)`). However, keep in mind that these results might not be representative of all possible environments or use cases.
Related benchmarks:
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?