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

Revision 2 of this 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;
}

// put forOf and for in functions for consistency
function forOfPush(a) {
  const nextArr = [];
  for (const v of a) {
    nextArr.push(v);
  }
  return nextArr;
}

function forISet(a) {
  const nextArr = Array(a.length);
  for (let i = 0; i < a.length; i++) {
	nextArr[i] = a[i];
  }
  return nextArr;
}

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
forOfPush(arr);
ready
for w/ preset array length
forISet(arr);
ready

Revisions

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