Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ES6 equivalent to lodash _.mapValues 2
(version: 0)
Comparing performance of:
native approach with reduce vs lodash mapValues
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/core.js"></script>
Tests:
native approach with reduce
var columns = ['a', 'b', 'c'] const table = { a: _.range(10000), b: _.range(10000), c: _.range(10000), } return _.range(10000).map((v, r) => { return columns.reduce((acc, c) => ({ ...acc, [c]: table[c][r] }), {}); });
lodash mapValues
var columns = ['a', 'b', 'c'] const table = { a: _.range(10000), b: _.range(10000), c: _.range(10000), } const emptyRow = { a: null, b: null, c: null } return _.range(10000).map((v, r) => { return _.mapValues(emptyRow, (v, c) => table[c][r]) });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native approach with reduce
lodash mapValues
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):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark is designed to compare two approaches for creating an array of objects with mapped values from a predefined array of columns (`"a"`, `"b"`, and `"c"`). The test cases are: "native approach with reduce" and "Lodash `mapValues`". **Native Approach with Reduce** In this approach, the benchmark uses the `reduce()` method to create an accumulator object that maps values from each column in the predefined array. Here's a simplified version of the code: ```javascript var columns = ['a', 'b', 'c'] const table = { /* ... */ } return _.range(10000).map((v, r) => { return columns.reduce((acc, c) => ({ ...acc, [c]: table[c][r] }), {}) }) ``` The benchmark measures the execution time of this approach. **Lodash `mapValues`** In this approach, Lodash is used to create an object with mapped values from a predefined array. Here's the relevant code snippet: ```javascript const emptyRow = { a: null, b: null, c: null } return _.range(10000).map((v, r) => { return _.mapValues(emptyRow, (v, c) => table[c][r]) }) ``` The benchmark measures the execution time of this approach. **What's being tested?** Both approaches are testing the performance of creating an array of objects with mapped values from a predefined array. The tests compare: 1. Native JavaScript implementation using `reduce()`. 2. Lodash `mapValues()` method. 3. Execution time (number of executions per second) for each approach. **Pros and Cons** * **Native Approach with Reduce**: + Pros: Lightweight, no dependencies on external libraries. + Cons: More complex implementation, may have performance overhead due to the use of `reduce()`. * **Lodash `mapValues`**: + Pros: Easy to implement, optimized for performance by Lodash's developers. + Cons: External dependency on Lodash library. **Library Usage** The benchmark uses Lodash's `mapValues()` method, which is a utility function for creating objects with mapped values from an existing object. The purpose of this function is to simplify the process of creating objects with dynamic key-value pairs. **Special JS Feature or Syntax** There are no special JavaScript features or syntax used in these benchmarks.
Related benchmarks:
lodash (v4.17.15) map vs Object.keys map
lodash vs es6 map
array.map vs _.map
lodash _.map vs native map true version
Ladash map versus ECMA6 map
Comments
Confirm delete:
Do you really want to delete benchmark?