Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chunk example is slower than lodash's chunk #392

Open
guoyunhe opened this issue Jan 29, 2024 · 0 comments
Open

chunk example is slower than lodash's chunk #392

guoyunhe opened this issue Jan 29, 2024 · 0 comments

Comments

@guoyunhe
Copy link

guoyunhe commented Jan 29, 2024

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant