Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0
Firefox 94
Windows
Desktop
3 years ago
Test name Executions per second
splice Recurcive 2.1 Ops/sec
splice While 37.0 Ops/sec
lodash chunk 35.5 Ops/sec
Script Preparation code:
x
 
var _list = [];
for (var i = 0; i < 1000 * 1000; i++) {
  _list.push(i);
}
var chunkR = (array, size) => array.length ? [array.splice(0,size), ...chunkR(array, size)]:[]
var chunkW = (array, size) => {
  const R = new Array(Math.ceil(array.length / size))
  while (array.length)
    R.push(array.splice(0, size))
  return R
}
// lodash shit 
function slice(array, start, end) {
  let length = array == null ? 0 : array.length
  if (!length) {
    return []
  }
  start = start == null ? 0 : start
  end = end === undefined ? length : end
  if (start < 0) {
    start = -start > length ? 0 : (length + start)
  }
  end = end > length ? length : end
  if (end < 0) {
    end += length
  }
  length = start > end ? 0 : ((end - start) >>> 0)
  start >>>= 0
  let index = -1
  const result = new Array(length)
  while (++index < length) {
    result[index] = array[index + start]
  }
  return result
}
function toInteger(value) {
  const result = (value)
  const remainder = result % 1
  return remainder ? result - remainder : result
}
function chunkL(array, size = 1) {
  size = Math.max(toInteger(size), 0)
  const length = array == null ? 0 : array.length
  if (!length || size < 1) {
    return []
  }
  let index = 0
  let resIndex = 0
  const result = new Array(Math.ceil(length / size))
  while (index < length) {
    result[resIndex++] = slice(array, index, (index += size))
  }
  return result
}
var list = [..._list]
Tests:
  • splice Recurcive

     
    const list = [..._list]
    const c = chunkR(list, 200)
    if (c.length != 5000) throw new Error('bad result')
  • splice While

     
    const list = [..._list]
    const c = chunkL(list, 200)
    if (c.length != 5000) throw new Error('bad result')
  • lodash chunk

     
    const list = [..._list]
    const c = chunkL(list, 200)
    if (c.length != 5000) throw new Error('bad result')