<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);
let mappedArray = [];
for(let i = 0, len = data.length; i < len; i++){
mappedArray.push(data[i]);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Ramda | |
Array (native) | |
For loop (native) |
Test name | Executions per second |
---|---|
Ramda | 1429450.8 Ops/sec |
Array (native) | 1893170.6 Ops/sec |
For loop (native) | 435500.5 Ops/sec |
Let's break down the provided benchmark definition and test cases.
Benchmark Definition
The website "MeasureThat.net" is testing the speed of three approaches to perform a simple mapping operation on an array:
R.map(double, data)
using Ramda's map
functiondata.map(double)
using the native map
method of JavaScript arraysfor(let i = 0, len = data.length; i < len; i++){\r\n mappedArray.push(data[i]);\r\n}
Options Compared
The benchmark is comparing the performance of these three approaches:
map
functionmap
methodPros and Cons of Each Approach
map
function: Pros:map
method: Pros:Library Usage
The benchmark uses Ramda's map
function from version 0.25.0. This is a functional programming library that provides various higher-order functions for manipulating data structures, including arrays. The purpose of using Ramda is to demonstrate the performance of its map
function in comparison to the native JavaScript array method.
Special JS Feature or Syntax
There are no special JavaScript features or syntax used in this benchmark beyond what's provided by the standard language specification.