<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((n) => n*2, data);
data.map(n => n*2);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Ramda | |
Array (native) |
Test name | Executions per second |
---|---|
Ramda | 1784471.1 Ops/sec |
Array (native) | 2660604.2 Ops/sec |
Let's break down the benchmark and its options.
Benchmark Definition
The benchmark is designed to measure the speed of two different approaches: Ramda's map
function and Array's native map
function with an anonymous function.
Options Compared
map
function: This approach uses the Ramda library, which provides a functional programming style for JavaScript.map
function: This approach is built into the JavaScript language itself and uses a closure-based approach to iterate over the array.Pros and Cons
map
function:map
function:Library: Ramda
Ramda is a popular functional programming library for JavaScript that provides a set of reusable functions for common data transformation tasks. In this benchmark, Ramda's map
function is used to double each element in the input array.
Special JS Feature/Syntax: None
There are no special JavaScript features or syntax used in this benchmark.
Other Alternatives
If you wanted to compare other approaches, you might consider:
map
function using traditional loops and callbacksforEach
Keep in mind that the choice of library or implementation can significantly impact performance. In this case, Ramda's map
function is optimized for performance, but the benchmark also provides a comparison with Array's native map
function to give users a sense of the overhead introduced by external libraries.