Skip to content

chunk example is slower than lodash's chunk #392

Open
@guoyunhe

Description

@guoyunhe

I did a performance test with vitest:

Source ops/sec (higher is better)
lodash 5.24m
you don't need lodash 4.31m
you might not need lodash 7.41m

So I think you should take a look at https://youmightnotneed.com/lodash/#chunk which is way more efficient than current example in this repo.

const chunk = (arr, chunkSize = 1, cache = []) => {
  const tmp = [...arr]
  if (chunkSize <= 0) return cache
  while (tmp.length) cache.push(tmp.splice(0, chunkSize))
  return cache
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions