Prefer Built in Methods

Benchmark created by BretCameron on


Setup

function map(arr, func) {
    const mapArr = [];
    for(let i = 0; i < arr.length; i++) {
      const result = func(arr[i], i, arr);
      mapArr.push(result);
    }
    return mapArr;
  };
  
  const arr = [...Array(100)].map(e=>~~(Math.random()*100));

Test runner

Ready to run.

Testing in
TestOps/sec
Our JavaScript map implementation
map(arr, el => el * 2);
ready
The built-in Array.protoype.map
arr.map(el => el * 2);
ready

Revisions

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

  • Revision 1: published by BretCameron on