chunk perf

Benchmark created on


Setup

const array = Array.from({ length: 1000 }, (_, i) => i);
const cs = 3;

Test runner

Ready to run.

Testing in
TestOps/sec
yuzu
let index = 0,
    result = Array(Math.trunc(array.length / cs)),
    resIndex = result.length;

while (index < array.length) {
  const item = array.slice(index, (index += cs));
  result[resIndex] = item;
  resIndex--;
}

console.log(result);
ready
g4
const chunks = [];

let i = 0;
while (i < array.length) {
  let y = 0;
  chunks[Math.floor(i/cs)] = [];
  while (i+y < array.length && y < cs) {
    let index = array.length - (i+y) - 1;
    chunks[Math.floor(i/cs)].push(array[index]);
    y += 1
  }
  i += cs;
}


console.log(chunks);
ready

Revisions

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