<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js'></script>
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*n, data);
data.map((n) => n*n);
_.map(data, (n) => n*n);
Immutable.fromJS(data).map((n) => n*n)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Ramda.map | |
Array.prototype.map | |
lodash.map | |
Immutable.map |
Test name | Executions per second |
---|---|
Ramda.map | 11877478.0 Ops/sec |
Array.prototype.map | 9251283.0 Ops/sec |
lodash.map | 19569794.0 Ops/sec |
Immutable.map | 1072676.5 Ops/sec |
Let's break down the provided benchmark and explain what's being tested.
Benchmark Overview
The benchmark compares the performance of different libraries' mapping functions on an array of numbers:
Array.prototype.map
_.map
)R.map
)Immutable.map
)Library Description and Purpose
_.map
is part of Lodash's core functionality, allowing users to map over arrays.R.map
is one of Ramda's primary mapping functions.Immutable.map
is part of Immutable.js's core functionality, allowing users to map over arrays.Native JavaScript Array.prototype.map
The native JavaScript implementation of the map()
method is being tested. This is the built-in function provided by the ECMAScript standard for mapping over arrays.
Pros:
Cons:
Array.prototype.map
only works on native arrays and does not provide the same level of functional programming support as libraries like Lodash or Ramda.Comparison Options
The benchmark compares different mapping functions across various libraries:
Array.prototype.map
_.map
)R.map
)Immutable.map
)Each library offers a unique approach to array manipulation, catering to specific use cases and personal preferences.
Pros and Cons:
Special JS Feature/ Syntax
This benchmark does not explicitly use any special JavaScript features or syntax. However, the use of functional programming libraries like Ramda and Immutable.js might appeal to developers familiar with those paradigms.
Other Alternatives
If you're looking for alternatives to these libraries, consider:
map()
support.In summary, the benchmark provides insight into how different libraries compare when it comes to mapping over arrays. Each library offers unique strengths and weaknesses, catering to specific use cases and developer preferences.