exec arr of funcs (no closure)

Benchmark created on


Setup

const len = 10;

const arr = [...Array(len).keys()];

const arr1 = arr.map(i => (n) => n + 1);

const arr2 = arr.slice(0, -1).map(i => (n) => n + 1);
arr2.push((n) => n + 1);

const arr3 = [];
for (let i = 0; i< arr.length; i++) {
  arr3[i] = (n) => n + 1;
}

const arr4 = [];
for (let i = 0; i< arr.length - 1; i++) {
  arr4[i] = (n) => n + 1;
}
arr4.push((n) => n + 1);

const exec = (arr) => {
  for (let i = 0; i < arr.length; i++) {
    r = arr[i](i);
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
map
exec(arr1)
ready
map + push
exec(arr2)
ready
for
exec(arr3)
ready
for + push
exec(arr4)
ready

Revisions

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