(simple) map - lodash, ramda, .map, and ramda's internal _map

Benchmark created on


Description

10_000 rows of 0-9_999

map x => x

as straightforward as it gets to measure as close to clock cycles as we can

Preparation HTML

<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.29.1/ramda.min.js" integrity="sha512-PVSAmDFNqey8GMII8s9rjjkCFvUgzfsfi8FCRxQa3TkPZfdjCIUM+6eAcHIFrLfW5CTFAwAYS4pzl7FFC/KE7Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Setup

const arr = Array(10_000)
  .fill(undefined)
  .map((_, i) => i);

// copy of ramda internal
function _ramdaMap(fn, functor) {
  var idx = 0;
  var len = functor.length;
  var result = Array(len);
  while (idx < len) {
    result[idx] = fn(functor[idx]);
    idx += 1;
  }
  return result;
}

Test runner

Ready to run.

Testing in
TestOps/sec
lodash map
_.map(arr, x => x);
ready
ramda map
R.map(x => x, arr);
ready
array#map
arr.map(x => x);
ready
ramda map curried
R.map(x => x)(arr);
ready
ramda _map
_ramdaMap(x => x, arr);
ready
for..of
const nextArr = [];
for (const v of arr) {
	nextArr.push(v);
}
ready
for w/ preset array length
const nextArr = Array(arr.length);
for (let i = 0; i < arr.length; i++) {
	nextArr[i] = arr[i];
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.