<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
function double(n) {
return n*2;
}
var data = [Array(20)].map((v, idx) => idx);
R.map(double, data);
data.map(double);
_.map(data, double);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Ramda | |
Array (native) | |
Lodash |
Test name | Executions per second |
---|---|
Ramda | 1350641.6 Ops/sec |
Array (native) | 1714043.5 Ops/sec |
Lodash | 1938639.6 Ops/sec |
Let's break down the benchmark and its test cases.
Benchmark Overview
The benchmark measures the performance of three different approaches to map over an array: Array.prototype.map()
(native JavaScript), Ramda's R.map()
, and Lodash's _.map()
.
Options Compared
map()
function on arrays.map()
function.map()
function as part of its _.map() method.Library and Its Purpose
map()
. Its purpose is to provide a collection of small, reusable functions that make common tasks easier.Special JS Feature/Syntax
There is no specific JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of different mapping approaches.
Other Alternatives
map()
functions.forEach()
, reduce()
, or filter()
with Array.prototype.slice()
, could be tested for performance.When choosing between these options, consider the specific requirements of your project, including:
Ultimately, the choice of mapping approach depends on your project's specific needs and your team's familiarity with these options.