Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions benchmarks/performance/difference.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { difference as differenceToolkit_ } from 'es-toolkit';
import { difference as differenceCompatToolkit_ } from 'es-toolkit/compat';
import { difference as differenceLodash_ } from 'lodash';
import { difference as differenceLodash_es } from 'lodash-es';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, there shouldn't be any performance differences between lodash-es and lodash, so I'm wondering what the reason was for adding it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

The page https://es-toolkit.dev/performance.html uses lodash-es to demonstrate the performance of es-toolkit. so I used lodash-es too


const differenceToolkit = differenceToolkit_;
const differenceCompatToolkit = differenceCompatToolkit_;
const differenceLodash = differenceLodash_;
const differenceLodashEs = differenceLodash_es;

describe('difference', () => {
bench('es-toolkit/difference', () => {
Expand All @@ -19,6 +21,10 @@ describe('difference', () => {
bench('lodash/difference', () => {
differenceLodash([1, 2, 3], [2]);
});

bench('lodash-es/difference', () => {
differenceLodashEs([1, 2, 3], [2]);
});
});

describe('difference/largeArray', () => {
Expand All @@ -36,4 +42,8 @@ describe('difference/largeArray', () => {
bench('lodash/difference', () => {
differenceLodash(largeArray, largeArray2);
});

bench('lodash-es/difference', () => {
differenceLodashEs(largeArray, largeArray2);
});
});
10 changes: 10 additions & 0 deletions benchmarks/performance/differenceWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { differenceWith as differenceWithToolkit_ } from 'es-toolkit';
import { differenceWith as differenceWithCompatToolkit_ } from 'es-toolkit/compat';
import { differenceWith as differenceWithLodash_ } from 'lodash';
import { differenceWith as differenceWithLodash_es } from 'lodash-es';

const differenceWithToolkit = differenceWithToolkit_;
const differenceWithCompatToolkit = differenceWithCompatToolkit_;
const differenceWithLodash = differenceWithLodash_;
const differenceWithLodashEs = differenceWithLodash_es;

describe('differenceWith', () => {
bench('es-toolkit/differenceWith', () => {
Expand All @@ -19,6 +21,10 @@ describe('differenceWith', () => {
bench('lodash/differenceWith', () => {
differenceWithLodash([1.2, 2.3, 3.4], [1.2], (x, y) => Math.floor(x) === Math.floor(y));
});

bench('lodash-es/differenceWith', () => {
differenceWithLodashEs([1.2, 2.3, 3.4], [1.2], (x, y) => Math.floor(x) === Math.floor(y));
});
});

describe('differenceWith/largeArray', () => {
Expand All @@ -36,4 +42,8 @@ describe('differenceWith/largeArray', () => {
bench('lodash/differenceWith', () => {
differenceWithLodash(largeArray, largeArray2, (x, y) => Math.floor(x) === Math.floor(y));
});

bench('lodash-es/differenceWith', () => {
differenceWithLodashEs(largeArray, largeArray2, (x, y) => Math.floor(x) === Math.floor(y));
});
});
10 changes: 10 additions & 0 deletions benchmarks/performance/dropRightWhile.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { dropRightWhile as dropRightWhileToolkit_ } from 'es-toolkit';
import { dropRightWhile as dropRightWhileToolkitCompat_ } from 'es-toolkit/compat';
import { dropRightWhile as dropRightWhileLodash_ } from 'lodash';
import { dropRightWhile as dropRightWhileLodash_es } from 'lodash-es';

const dropRightWhileToolkit = dropRightWhileToolkit_;
const dropRightWhileToolkitCompat = dropRightWhileToolkitCompat_;
const dropRightWhileLodash = dropRightWhileLodash_;
const dropRightWhileLodashEs = dropRightWhileLodash_es;

describe('dropRightWhile', () => {
bench('es-toolkit/dropRightWhile', () => {
Expand All @@ -19,6 +21,10 @@ describe('dropRightWhile', () => {
bench('lodash/dropRightWhile', () => {
dropRightWhileLodash([1.2, 2.3, 3.4], x => x < 2);
});

bench('lodash-es/dropRightWhile', () => {
dropRightWhileLodashEs([1.2, 2.3, 3.4], x => x < 2);
});
});

describe('dropRightWhile/largeArray', () => {
Expand All @@ -35,4 +41,8 @@ describe('dropRightWhile/largeArray', () => {
bench('lodash/dropRightWhile', () => {
dropRightWhileLodash(largeArray, x => x < 5000);
});

bench('lodash-es/dropRightWhile', () => {
dropRightWhileLodashEs(largeArray, x => x < 5000);
});
});
18 changes: 18 additions & 0 deletions benchmarks/performance/groupBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { groupBy as groupByToolkit_ } from 'es-toolkit';
import { groupBy as groupByToolkitCompat_ } from 'es-toolkit/compat';
import { groupBy as groupByLodash_ } from 'lodash';
import { groupBy as groupByLodash_es } from 'lodash-es';

const groupByToolkit = groupByToolkit_;
const groupByToolkitCompat = groupByToolkitCompat_;
const groupByLodash = groupByLodash_;
const groupByLodashEs = groupByLodash_es;

describe('groupBy', () => {
bench('es-toolkit/groupBy', () => {
Expand Down Expand Up @@ -43,6 +45,18 @@ describe('groupBy', () => {

groupByLodash(array, item => item.category);
});

bench('lodash-es/groupBy', () => {
const array = [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' },
{ category: 'vegetable', name: 'carrot' },
{ category: 'fruit', name: 'pear' },
{ category: 'vegetable', name: 'broccoli' },
];

groupByLodashEs(array, item => item.category);
});
});

describe('groupBy/largeArray', () => {
Expand All @@ -58,4 +72,8 @@ describe('groupBy/largeArray', () => {
bench('lodash/groupBy', () => {
groupByLodash(largeArray, item => item.category);
});

bench('lodash-es/groupBy', () => {
groupByLodashEs(largeArray, item => item.category);
});
});
10 changes: 10 additions & 0 deletions benchmarks/performance/intersection.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { intersection as intersectionToolkit_ } from 'es-toolkit';
import { intersection as intersectionCompatToolkit_ } from 'es-toolkit/compat';
import { intersection as intersectionLodash_ } from 'lodash';
import { intersection as intersectionLodash_es } from 'lodash-es';

const intersectionToolkit = intersectionToolkit_;
const intersectionCompatToolkit = intersectionCompatToolkit_;
const intersectionLodash = intersectionLodash_;
const intersectionLodashEs = intersectionLodash_es;

describe('intersection, small arrays', () => {
const array1 = [1, 2, 3];
Expand All @@ -22,6 +24,10 @@ describe('intersection, small arrays', () => {
bench('lodash/intersection', () => {
intersectionLodash(array1, array2);
});

bench('lodash-es/intersection', () => {
intersectionLodashEs(array1, array2);
});
});

describe('intersection, large arrays', () => {
Expand All @@ -39,4 +45,8 @@ describe('intersection, large arrays', () => {
bench('lodash/intersection', () => {
intersectionLodash(array1, array2);
});

bench('lodash-es/intersection', () => {
intersectionLodashEs(array1, array2);
});
});
13 changes: 13 additions & 0 deletions benchmarks/performance/intersectionWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { intersectionWith as intersectionWithToolkit_ } from 'es-toolkit';
import { intersectionWith as intersectionWithCompat_ } from 'es-toolkit/compat';
import { intersectionWith as intersectionWithLodash_ } from 'lodash';
import { intersectionWith as intersectionWithLodash_es } from 'lodash-es';

const intersectionWithToolkit = intersectionWithToolkit_;
const intersectionWithCompat = intersectionWithCompat_;
const intersectionWithLodash = intersectionWithLodash_;
const intersectionWithLodashEs = intersectionWithLodash_es;

describe('intersectionWith', () => {
bench('es-toolkit/intersectionWith', () => {
Expand All @@ -28,6 +30,13 @@ describe('intersectionWith', () => {
const areItemsEqual = (a, b) => a.id === b.id;
intersectionWithLodash(array1, array2, areItemsEqual);
});

bench('lodash-es/intersectionWith', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const areItemsEqual = (a, b) => a.id === b.id;
intersectionWithLodashEs(array1, array2, areItemsEqual);
});
});

describe('intersectionWith/largeArrays', () => {
Expand All @@ -46,4 +55,8 @@ describe('intersectionWith/largeArrays', () => {
bench('lodash/intersectionWith', () => {
intersectionWithLodash(array1, array2, areItemsEqual);
});

bench('lodash-es/intersectionWith', () => {
intersectionWithLodashEs(array1, array2, areItemsEqual);
});
});
10 changes: 10 additions & 0 deletions benchmarks/performance/omit.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { omit as omitToolkit_ } from 'es-toolkit';
import { omit as omitToolkitCompat_ } from 'es-toolkit/compat';
import { omit as omitLodash_ } from 'lodash';
import { omit as omitLodash_es } from 'lodash-es';

const omitToolkit = omitToolkit_;
const omitToolkitCompat = omitToolkitCompat_;
const omitLodash = omitLodash_;
const omitLodashEs = omitLodash_es;

describe('omit: simple', () => {
bench('es-toolkit/omit', () => {
Expand All @@ -19,6 +21,10 @@ describe('omit: simple', () => {
bench('lodash/omit', () => {
omitLodash({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});

bench('lodash-es/omit', () => {
omitLodashEs({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});
});

describe('omit: complex', () => {
Expand All @@ -29,4 +35,8 @@ describe('omit: complex', () => {
bench('lodash/omit', () => {
omitLodash({ foo: { bar: { baz: 1 } }, quux: 2, a: { b: 3 } }, ['foo.bar.baz', 'quux']);
});

bench('lodash-es/omit', () => {
omitLodashEs({ foo: { bar: { baz: 1 } }, quux: 2, a: { b: 3 } }, ['foo.bar.baz', 'quux']);
});
});
6 changes: 6 additions & 0 deletions benchmarks/performance/pick.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { pick as pickToolkit_ } from 'es-toolkit';
import { pick as pickCompatToolkit_ } from 'es-toolkit/compat';
import { pick as pickLodash_ } from 'lodash';
import { pick as pickLodash_es } from 'lodash-es';

const pickToolkit = pickToolkit_;
const pickCompatToolkit = pickCompatToolkit_;
const pickLodash = pickLodash_;
const pickLodashEs = pickLodash_es;

describe('pick', () => {
bench('es-toolkit/pick', () => {
Expand All @@ -19,4 +21,8 @@ describe('pick', () => {
bench('lodash/pick', () => {
pickLodash({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});

bench('lodash-es/pick', () => {
pickLodashEs({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});
});
12 changes: 12 additions & 0 deletions benchmarks/performance/union.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { union as unionToolkit_ } from 'es-toolkit';
import { union as unionToolkitCompat_ } from 'es-toolkit/compat';
import { union as unionLodash_ } from 'lodash';
import { union as unionLodash_es } from 'lodash-es';

const unionToolkit = unionToolkit_;
const unionToolkitCompat = unionToolkitCompat_;
const unionLodash = unionLodash_;
const unionLodashEs = unionLodash_es;

describe('union', () => {
bench('es-toolkit/union', () => {
Expand All @@ -25,6 +27,12 @@ describe('union', () => {
const array2 = [3, 4, 5];
unionLodash(array1, array2);
});

bench('lodash-es/union', () => {
const array1 = [1, 2, 3];
const array2 = [3, 4, 5];
unionLodashEs(array1, array2);
});
});

describe('union/largeArray', () => {
Expand All @@ -42,4 +50,8 @@ describe('union/largeArray', () => {
bench('lodash/union', () => {
unionLodash(largeArray1, largeArray2);
});

bench('lodash-es/union', () => {
unionLodashEs(largeArray1, largeArray2);
});
});
10 changes: 10 additions & 0 deletions benchmarks/performance/unionBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { bench, describe } from 'vitest';
import { unionBy as unionByToolkit_ } from 'es-toolkit';
import { unionBy as unionByToolkitCompat_ } from 'es-toolkit/compat';
import { unionBy as unionByLodash_ } from 'lodash';
import { unionBy as unionByLodash_es } from 'lodash-es';

const unionByToolkit = unionByToolkit_;
const unionByToolkitCompat = unionByToolkitCompat_;
const unionByLodash = unionByLodash_;
const unionByLodashEs = unionByLodash_es;

describe('unionBy', () => {
const array1 = [{ id: 1 }, { id: 2 }];
Expand All @@ -23,6 +25,10 @@ describe('unionBy', () => {
bench('lodash/unionBy', () => {
unionByLodash(array1, array2, getId);
});

bench('lodash-es/unionBy', () => {
unionByLodashEs(array1, array2, getId);
});
});

describe('unionBy/largeArray', () => {
Expand All @@ -41,4 +47,8 @@ describe('unionBy/largeArray', () => {
bench('lodash/unionBy', () => {
unionByLodash(largeArray1, largeArray2, getId);
});

bench('lodash-es/unionBy', () => {
unionByLodashEs(largeArray1, largeArray2, getId);
});
});
28 changes: 12 additions & 16 deletions docs/ja/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ description: es-toolkitと他のライブラリのパフォーマンスの違い

# パフォーマンス

![es-toolkitとlodashのパフォーマンスの違いを示すグラフ。es-toolkitを使用すると、最大11倍のパフォーマンス向上が得られます。](/assets/performance.png)

パフォーマンスを重視して設計されたes-toolkitは、lodashのような他のライブラリと比較して平均2倍のパフォーマンス向上を提供します。いくつかの関数は、最新のJavaScript APIを完全に活用することで、最大11倍のパフォーマンス向上を達成します。
パフォーマンスを重視して設計されたes-toolkitは、lodashのような他のライブラリと比較して平均2倍のパフォーマンス向上を提供します。

## パフォーマンス比較

| | [email protected] | [email protected] | Difference |
| --------------------------------------------------------- | ---------------- | ----------------- | ---------- |
| [omit](./reference/object/omit.md) | 4,767,360 times | 403,624 times | 11.8× |
| [pick](./reference/object/pick.md) | 9,121,839 times | 2,663,072 times | 3.43× |
| [differenceWith](./reference/array/differenceWith.md) | 9,291,897 times | 4,275,222 times | 2.17× |
| [difference](./reference/array/difference.md) | 10,436,101 times | 5,155,631 times | 2.02× |
| [intersectionWith](./reference/array/intersectionWith.md) | 8,074,722 times | 3,814,479 times | 2.12× |
| [intersection](./reference/array/intersection.md) | 9,999,571 times | 4,630,316 times | 2.15× |
| [unionBy](./reference/array/unionBy.md) | 6,435,983 times | 3,794,899 times | 1.69× |
| [union](./reference/array/union.md) | 5,059,209 times | 4,771,400 times | 1.06× |
| [dropRightWhile](./reference/array/dropRightWhile.md) | 7,529,559 times | 5,606,439 times | 1.34× |
| [groupBy](./reference/array/groupBy.md) | 5,000,235 times | 5,206,286 times | 0.96× |
| | [email protected] | [email protected] | Difference |
| --------------------------------------------------------- | ----------------- | ----------------- | ---------- |
| [omit](./reference/object/omit.md) | 5,522,023 times | 1,598,902 times | 3.45x |
| [pick](./reference/object/pick.md) | 11,548,374 times | 2,507,413 times | 4.61x |
| [differenceWith](./reference/array/differenceWith.md) | 18,559,083 times | 4,648,750 times | 3.99x |
| [difference](./reference/array/difference.md) | 13,838,471 times | 5,605,974 times | 2.47x |
| [intersectionWith](./reference/array/intersectionWith.md) | 14,160,477 times | 4,100,403 times | 3.87x |
| [intersection](./reference/array/intersection.md) | 12,555,311 times | 5,442,531 times | 2.31x |
| [unionBy](./reference/array/unionBy.md) | 6,116,069 times | 4,210,245 times | 1.76x |
| [dropRightWhile](./reference/array/dropRightWhile.md) | 18,924,422 times | 11,115,819 times | 1.70x |

テスト環境はMacBook Pro 14インチ(M1 Max2021です。[ベンチマークコード](https://github.com/toss/es-toolkit/tree/main/benchmarks)を参照してください。
テスト環境はMacBook Pro 16-inch (M1 Max, 2021)です。[ベンチマークコード](https://github.com/toss/es-toolkit/tree/main/benchmarks)を参照してください。
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The Japanese text should use consistent formatting for 'MacBook Pro 16-inch'. Consider using Japanese parentheses () instead of English parentheses () for consistency with Japanese typography conventions, or maintain the English format consistently as in the original.

Suggested change
テスト環境はMacBook Pro 16-inch (M1 Max, 2021)です。[ベンチマークコード](https://github.com/toss/es-toolkit/tree/main/benchmarks)を参照してください。
テスト環境はMacBook Pro 16-inchM1 Max, 2021です。[ベンチマークコード](https://github.com/toss/es-toolkit/tree/main/benchmarks)を参照してください。

Copilot uses AI. Check for mistakes.
Loading