toss / es-toolkit

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.
https://es-toolkit.slash.page
Other
6.25k stars 263 forks source link

refactor(tail): Improve code readability in `tail` #443

Closed mass2527 closed 2 weeks ago

mass2527 commented 2 weeks ago

this change not only improve code readability but also improve performance in large array.

i ran this bench to check tail in large array

import { bench, describe } from 'vitest';
import { tail as tailToolkit } from 'es-toolkit';
import { tail as tailLodash } from 'lodash';

// Helper function to generate a large array
function generateLargeArray(size) {
  return Array.from({ length: size }, (_, index) => index);
}

describe('tail', () => {
  const largeArray = generateLargeArray(1000000);

  bench('es-toolkit/tail', () => {
    tailToolkit(largeArray);
  });

  bench('lodash/tail', () => {
    tailLodash(largeArray);
  });
});

updated code is more faster than original code.

before

스크린샷 2024-08-29 오후 10 02 55

after

스크린샷 2024-08-29 오후 10 02 42
vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2024 1:09pm
codecov-commenter commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.77%. Comparing base (b9966aa) to head (f2b628f).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/toss/es-toolkit/pull/443/graphs/tree.svg?width=650&height=150&src=pr&token=8N5S3AR3C7&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toss)](https://app.codecov.io/gh/toss/es-toolkit/pull/443?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toss) ```diff @@ Coverage Diff @@ ## main #443 +/- ## ========================================== - Coverage 99.77% 99.77% -0.01% ========================================== Files 165 165 Lines 1325 1321 -4 Branches 357 357 ========================================== - Hits 1322 1318 -4 Misses 2 2 Partials 1 1 ```