Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash map vs Object.values map
(version: 0)
lodash map vs Object.values map
Comparing performance of:
lodash.map vs native
Created:
6 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.map
_.map(value, (v) => v)
native
Object.entries(value).map((v) => v)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash.map
native
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash.map
7465056.5 Ops/sec
native
9061339.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down the provided JSON and benchmark results. **Benchmark Description** The benchmark compares the performance of two approaches to iterating over an object's properties: 1. Using Lodash's `_.map()` function 2. Using native JavaScript's `Object.entries()`, followed by the `map()` method **Test Case 1: Lodash.map** * Benchmark Definition: `_.map(value, (v) => v)` * Test Name: "lodash.map" * Library Used: Lodash * Purpose of Library: A popular utility library for functional programming, providing a lot of useful functions for tasks like array and object manipulation. * Special JS Feature or Syntax: None mentioned in this test case. The test case uses the `_.map()` function from Lodash to iterate over the properties of an object (`value`). This approach is likely using the optimized iteration method provided by Lodash, which might be faster than native JavaScript methods due to its performance-tuned implementation. **Test Case 2: Native** * Benchmark Definition: `Object.entries(value).map((v) => v)` * Test Name: "native" * Library Used: None * Purpose of Library: N/A * Special JS Feature or Syntax: `Object.entries()` (introduced in ECMAScript 2017) The test case uses the native JavaScript method `Object.entries()` to get an array of key-value pairs from the object (`value`). It then applies the `map()` method to this array. The expression `(v) => v` is a simple identity function, which returns its input unchanged. In modern browsers (Chrome 121 in this case), the `Object.entries()` method is optimized and can be faster than traditional iteration methods like `for...in`. However, it's worth noting that older browsers might not support this feature or have slower performance. **Benchmark Results** The latest benchmark results show: * For "native" test case: approximately 8.04 million executions per second * For "lodash.map" test case: approximately 6.78 million executions per second These results indicate that the native JavaScript approach using `Object.entries()` and `map()` is faster than the Lodash-based implementation. **Alternatives** Other alternatives to achieve similar functionality include: 1. Using a simple `for...in` loop: ```javascript for (const key in value) { const v = value[key]; // do something with v } ``` However, this approach might be slower due to the overhead of the loop and property access. 2. Utilizing other libraries or frameworks that provide optimized iteration methods, such as Underscore.js (similar to Lodash). Keep in mind that these alternatives are not compared in this benchmark. If you're interested in exploring further performance differences, feel free to add more test cases!
Related benchmarks:
lodash 4.17.2 map vs Object.keys map
lodash.values vs Object.values
lodash (v4.17.15) map vs Object.keys map
lodash 4.17.15 map vs Object.keys map
lodash map vs Object.keys map vs Object.values
Comments
Confirm delete:
Do you really want to delete benchmark?