Chunk slice vs. Lodash chunk

5 months ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Test name Executions per second
Chunk by slice 15185287.0 Ops/sec
lodash chunk 157.2 Ops/sec
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 test = Array.from({
    length: 1000000
}, () => Math.random())
function chunkSlice(raw, chunkSize) {
  const groups = [];
  let i = 0;
  while (i < raw.length) {
    groups.push(raw.slice(i, (i += chunkSize)));
  }
  return groups;
}
Tests:
  • Chunk by slice

     
    chunkSlice(0,500)
  • lodash chunk

     
    _.chunk(test,500)
Open this result on MeasureThat.net