Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object values vs lodash _.values
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Object values vs _.values
Created:
4 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
var a = { a: {pk: '1', bounding: {left: 34, right: 32}}, b: {pk: '2', bounding: {left: 32, right: 34}}, c: {pk: '3', bounding: {left: 2, right: 1}}}; Object.values(a);
_.values
var a = { a: {pk: '1', bounding: {left: 34, right: 32}}, b: {pk: '2', bounding: {left: 32, right: 34}}, c: {pk: '3', bounding: {left: 2, right: 1}}}; _.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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object values
10256832.0 Ops/sec
_.values
9459119.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and considered. **Benchmark Overview** The benchmark is designed to compare the performance of two approaches: 1. Using the new ES6 spread operator (`Object.values()`). 2. Using the `_.values()` method from the Lodash library. **What's Being Tested** The benchmark tests the execution time of two test cases, each with an object containing nested objects with `pk` and `bounding` properties. The test cases use different methods to extract values from these objects: 1. **Object.values()**: Using the spread operator (`...`) to create a new array containing all enumerable property values of the object. 2. **_.values()` (Lodash)**: A utility function that returns an array of values extracted from an object. **Options Compared** The benchmark compares the performance of two approaches: 1. **Object.values()**: Using the native JavaScript spread operator. 2. **_.values()` (Lodash)**: Using a library-specific implementation. **Pros and Cons** **Object.values():** Pros: * Native JavaScript support, no additional dependencies required. * Potential for better caching and optimization by the browser's JavaScript engine. Cons: * May not be supported in older browsers or environments without ES6 syntax. * Might have varying performance characteristics depending on the JavaScript engine used. **_.values() (Lodash):** Pros: * Widely supported across various browsers and environments due to Lodash's popularity. * Can provide a more consistent experience, as it uses a standardized implementation. Cons: * Requires an additional library dependency, which might incur overhead. * May not leverage the browser's JavaScript engine optimizations as effectively as `Object.values()`. **Library - Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object iteration, and more. In this benchmark, `_` refers to the Lodash root object, which contains several utility functions, including `.values()`. Lodash's purpose is to simplify common programming tasks by providing a standardized set of algorithms and data structures. **Other Considerations** * **Browser Optimizations**: Modern browsers often use techniques like Just-In-Time (JIT) compilation and caching to optimize JavaScript performance. This might affect the benchmark results, as the browser's engine may be able to optimize `Object.values()` more efficiently than _.values(). * **Test Environment**: The test environment's specifics, such as CPU architecture, memory constraints, or specific JavaScript engine versions, can influence the benchmark results. **Alternatives** Other alternatives for extracting values from objects might include: 1. Using a library like Immutable.js, which provides immutable data structures and utility functions. 2. Implementing custom iteration logic using `for...in` loops or `Array.prototype.forEach()`. 3. Using other JavaScript libraries or frameworks that provide similar functionality to Lodash. Keep in mind that the choice of approach often depends on the specific use case, performance requirements, and personal preference.
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
Comments
Confirm delete:
Do you really want to delete benchmark?