HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
x
 
var arr = [];
var size = 10
for (let i = 0; i < 1E6; i++) {
  arr.push(i);
}
Tests:
  • chunks by reduceRight

     
    const result = arr.reduceRight((res,_,__,self) => [...res, self.splice(0, size)],[]);
  • chunks by lodash

     
    _.chunk(arr, 10);
  • splice from the beginning

     
    const result = [];
    while (arr.length) {
      const chunk = arr.splice(0, size)
      result.push(chunk);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    chunks by reduceRight
    chunks by lodash
    splice from the beginning

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Chrome 116 on Windows
View result in a separate tab
Test name Executions per second
chunks by reduceRight 13165212.0 Ops/sec
chunks by lodash 4925377.0 Ops/sec
splice from the beginning 13880723.0 Ops/sec