<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
function double(n) {
return n*2;
}
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
R.map(double, data);
data.map(double);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Ramda | |
Array (native) |
Test name | Executions per second |
---|---|
Ramda | 1847403.9 Ops/sec |
Array (native) | 2234207.0 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks!
The provided benchmark compares two approaches: Array.map
(also known as the native map function) and R.map
from the Ramda library.
What are they compared?
In this benchmark, both Array.map
and R.map
are applied to a large array (data
) with 30 elements. The map
function takes two arguments: a callback function (in this case, double(n)
) that returns a new value for each element in the array.
Options being compared
Here's a brief overview of what's being tested:
map
function. While it's based on the native implementation, it adds some extra features and sugar.Pros and Cons
Here are some pros and cons of each approach:
Native Array.map:
Pros:
Array.map
Cons:
R.map from Ramda library:
Pros:
Cons:
Array.map
function due to overhead from the JavaScript engineLibrary explanation
In this benchmark, Ramda is a functional programming library that provides an implementation of the map
function. Its purpose is to provide a more expressive and concise way to perform functions on arrays.
Special JS feature or syntax
There isn't any special JavaScript feature or syntax being used in this benchmark beyond what's already mentioned (e.g., Array.map
, Ramda's R.map
).