Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.values vs lodash values
(version: 0)
comparing performance of Object.values vs lodash values
Comparing performance of:
Object.values vs Lodash values
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var object = {}; for (let i = 0; i < 100000; i++) { object['key' + i] = i; }
Tests:
Object.values
Object.values(object);
Lodash values
_.values(object);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.values
Lodash values
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.values
38.0 Ops/sec
Lodash values
56.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the benchmark. **Benchmark Overview** The provided benchmark is designed to compare the performance of two methods: `Object.values` and `_.values` (using Lodash library). The benchmark measures how many iterations can be performed per second on a given object. **What is being tested?** In this case, the test is comparing the speed of two approaches: 1. **Native JavaScript**: Using the built-in `Object.values()` method to retrieve the values from an object. 2. **Lodash library**: Using the `_.values()` function from the Lodash library to achieve a similar result. **Options compared** The benchmark compares the performance of these two options on a specific object created with 100,000 properties. **Pros and Cons of each approach:** 1. **Native JavaScript (Object.values())** * Pros: + Built-in method, so no additional library dependencies. + Typically faster since it's implemented in native code. * Cons: + Might not be as readable or maintainable due to its simplicity. 2. **Lodash library (.values())** * Pros: + More readable and maintainable, especially for complex object operations. + Provides a familiar API for those familiar with Lodash. * Cons: + Requires an additional library dependency (Lodash), which might incur overhead. **Library description: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object transformation, and more. The `_.values()` function is one of these utilities, providing a convenient way to retrieve the values from an object without using native methods like `Object.values()`. **Special JS feature: ES6** The benchmark uses ES6 syntax, specifically the arrow function (`for (let i = 0; i < 100000; i++)`) and template literals (`object['key' + i] = i`). These features are part of the ECMAScript 2015 standard and provide a concise way to write code. **Other alternatives** If you're looking for alternative methods to retrieve object values, some options include: 1. **Array.prototype.map()**: Although not directly applicable here, it could be used if the object's keys could be converted into an array. 2. **Object.keys() and Array.prototype.forEach()**: You can use `Object.keys()` to get an array of keys and then use `forEach()` with a callback function to iterate over them. Keep in mind that these alternatives might not offer the same performance or readability as `Object.values()` or `_.values()`. **Benchmark result interpretation** The benchmark results show two runs: one for `Lodash values` (with 56.717 iterations per second) and one for `Object.values` (with 37.993 iterations per second). The Lodash version performs slightly better on this specific test case, likely due to the optimized implementation of the `_values()` function within the library.
Related benchmarks:
lodash.keys vs Object.keys
Loop over object: lodash vs Object.entries vs Object.keys vs Object.values
Loop over object: lodash vs Object.entries vs Object.values vs Object.keys (lodash 4.17.15)
Loop over object: lodash.forOwn vs Object.keys().forEach
Comments
Confirm delete:
Do you really want to delete benchmark?