mapping strategies when chunking

JavaScript performance comparison

Test case created by tiagojpdias

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const chunkAndMap = (arr, size) => (
    size >= arr.length
    ? arr
    : Array.from(
      { length: Math.ceil(arr.length / size) },
      (_, i) => arr.slice(i * size, i * size + size)
    )
  );
  
  const chunk = (arr, size) => Array.from({ length: Math.ceil(arr.length / size) });
  
  const size = 10000000;
  const chunkSize = 100;
  
  const arr = Array(size);

};
</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
chunkAndMap
chunkAndMap(arr, chunkSize);
pending…
chunk and then map
chunk(arr, chunkSize).map((_, i) => arr.slice(i * size, i * size + size));
pending…

Revisions

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

0 Comments