<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(10001)].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 | 74202.5 Ops/sec |
Array (native) | 12834.8 Ops/sec |
Lodash | 65771.3 Ops/sec |
Let's break down the benchmark and explain what is being tested.
Benchmark Overview
The benchmark measures the speed of three different approaches to perform a map operation on an array:
R.map
map
function in JavaScript (i.e., Array.prototype.map())_.map
Options Compared
In this benchmark, we have two main options compared for each approach:
data.map(double)
)R.map(double, data)
)For Lodash, the comparison is between its native map function and Ramda's map function.
Pros and Cons of Each Approach
Native JavaScript Array Method
Ramda's R.map
Lodash's _map
Other Considerations
When choosing between these approaches, consider the following:
Library Usage
The benchmark uses two libraries:
R.map
function._map
function.Special JS Features or Syntax
There are no special JavaScript features or syntax used in this benchmark beyond what is required by the map
function itself.