JavaScript Array Map Performance

JavaScript performance comparison

Test case created by me4502

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function inlineMap(arr, f) {
    for (let i = 0; i < arr.length; i++) {
      arr[i] = f(arr[i]);
    }
    return arr;
  }
  
  const data = Array.from({ length: 10000}, (v, i) => ({
    id: `${i}`,
    data: i
  }));

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Native map
data.map(i => ({
  id: i.id,
  data: i.data * 2
}));
pending…
Inline Map
inlineMap(data, i => ({
  id: i.id,
  data: i.data * 2
}));
pending…
Inline Map (No Alloc)
inlineMap(data, i => {
  i.data *= 2;
  return i;
});
pending…

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

0 Comments