Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs js mapValues test
(version: 0)
Comparing performance of:
lodash vs js object fromEntries vs reduce
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var fruits = { 'apple': { 'name': 'apple', 'number': 5 }, 'orange': { 'name': 'orange', 'number': 10 } };
Tests:
lodash
_.mapValues(fruits, 'number');
js object fromEntries
Object.fromEntries( Object.entries(fruits).map(([key, { number }]) => [key, number]) )
reduce
Object.entries(fruits) .reduce((a, [key, { number }]) => { a[key] = number; return a; }, {} )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
js object fromEntries
reduce
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):
I'll break down the provided benchmark definition and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Description** The benchmark measures the performance of three different approaches to extract values from an object using JavaScript: 1. Lodash's `mapValues` function 2. The `Object.fromEntries` method with a callback function 3. A custom implementation using the `reduce` method **Options Compared** * **Lodash's `mapValues`**: A popular utility library that provides a convenient way to transform objects. * **`Object.fromEntries`**: A modern JavaScript method introduced in ECMAScript 2015 (ES6) for creating objects from arrays of key-value pairs. * **Custom implementation using `reduce`**: A vanilla JavaScript approach that uses the `reduce` method to iterate over an object's entries. **Pros and Cons** * **Lodash's `mapValues`**: + Pros: Convenient, readable code; well-tested and widely adopted library. + Cons: Adds an external dependency (the Lodash library); may not be optimized for performance in all scenarios. * **`Object.fromEntries`**: + Pros: Fast and efficient; no external dependencies; widely supported by modern browsers. + Cons: May require additional setup or compatibility considerations for older browsers. * **Custom implementation using `reduce`**: + Pros: Vanilla JavaScript, no external dependencies; potentially optimized for performance in certain scenarios. + Cons: May be less readable or maintainable than the other two options; requires more expertise with the `reduce` method. **Library and Syntax** In this benchmark, Lodash is used as a library to provide the `mapValues` function. The `Object.fromEntries` method is a native JavaScript API introduced in ES6. There are no special JS features or syntaxes mentioned in this benchmark. **Alternative Approaches** Other approaches to extract values from an object using JavaScript might include: * Using `forEach`: `obj.keys().forEach(key => console.log(obj[key]));` * Using `for...in` loops: `var result = {}; for (var key in obj) { result[key] = obj[key]; }` * Using other library functions, such as jQuery's `.each()` method or a custom implementation using recursion. Keep in mind that the performance of these alternative approaches may vary depending on the specific use case and requirements.
Related benchmarks:
Object.keys vs lodash _.keys
lodash (v4.17.15) map vs Object.keys map
Array.prototype.map vs Lodash.map on large data
array.map vs _.map
lodash map vs native map wraig0
Comments
Confirm delete:
Do you really want to delete benchmark?