Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash map vs es6 map v2
(version: 5)
Comparing performance of:
lodash map vs native map vs lodash reduce vs native reduce
Created:
7 years 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:
const j = [1, 4, 9, 16, 25, 35, 49, 68, 74, 86, 93, 110, 121, 135, 141, 156, 157, 158, 161, 162, 163, 164, 165, 166, 167, 168] function lodashmap () { arr = _.map(j, function(el){ return el * 10 }) console.log(arr) } function jsmap () { arr = j.map(function(el){ return el * 10 }) console.log(arr) } function lodashreduce () { arr = _.reduce(j, (els, el) => { els.push(el * 10) // console.log(els) return els }, []) console.log(arr) } function jsreduce () { arr = j.reduce(function(els, el) { els.push(el * 10) return els }, []) console.log(arr) }
Tests:
lodash map
lodashmap()
native map
jsmap()
lodash reduce
lodashreduce()
native reduce
jsreduce()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lodash map
native map
lodash reduce
native reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash map
173238.2 Ops/sec
native map
158922.0 Ops/sec
lodash reduce
147440.8 Ops/sec
native reduce
124861.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Definition JSON:** The provided JSON represents a benchmark test case for comparing the performance of two approaches: 1. **Lodash map**: uses the `_map` function from the Lodash library to transform an array. 2. **Native map (ES6)**: uses the built-in `map()` method of JavaScript arrays to achieve the same result. Both approaches are used in conjunction with a second function, `reduce()`, which is also compared between two implementations: 1. **Lodash reduce**: uses the `_reduce` function from Lodash to accumulate values in an array. 2. **Native reduce (ES6)**: uses the built-in `reduce()` method of JavaScript arrays for the same purpose. **Options Compared:** The benchmark compares the performance of the following options: * Lodash map vs Native map (ES6) * Lodash reduce vs Native reduce (ES6) **Pros and Cons:** Here's a brief summary of the pros and cons of each approach: 1. **Lodash map**: * Pros: easier to read and write, especially for developers familiar with functional programming concepts. * Cons: requires an additional library dependency, which may add overhead in certain scenarios. 2. **Native map (ES6)**: * Pros: built-in method, no additional library dependencies required. * Cons: syntax might be less readable for some developers, especially those without prior experience with ES6. 1. **Lodash reduce**: * Pros: concise and expressive syntax, well-suited for accumulating values in an array. * Cons: still requires the Lodash library dependency. 2. **Native reduce (ES6)**: * Pros: similar to native map, no additional library dependencies required. * Cons: syntax might be less readable for some developers. **Library and Purpose:** The Lodash library provides a set of utility functions that make common programming tasks easier. In this benchmark, the `_map` and `_reduce` functions are used to transform and accumulate arrays, respectively. The library is widely used in JavaScript development due to its extensive feature set and convenient syntax. **Special JS Feature or Syntax:** The benchmark uses ES6 features (such as `const`, arrow functions, and template literals) to write the test code. These features provide a concise way of writing code and are commonly used in modern JavaScript applications. **Other Alternatives:** If you're looking for alternatives to Lodash, here are some popular options: * **Underscore.js**: another popular utility library that provides many of the same functions as Lodash. * **Moment.js**: a library for working with dates and times, which can be used in conjunction with other libraries or built-in methods. Keep in mind that these alternatives may have different syntax and features compared to Lodash, so it's essential to choose the one that best fits your project's needs. In summary, this benchmark provides a useful comparison of two approaches for transforming arrays: Lodash map vs Native map (ES6), and Lodash reduce vs Native reduce (ES6). The results will help you understand the performance differences between using a library versus built-in methods in JavaScript.
Related benchmarks:
Moz lodash map vs es6 map
Ladash map versus ECMA6 map
lodash map vs js map
lodash map vs es6 Object.values.map
Comments
Confirm delete:
Do you really want to delete benchmark?