mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 20:26:33 +03:00
3cb5c804e1
* feat: memoize * test: memoize * chore: add benchmark of memoize * docs: add docs * feat: add overloads to memoize * feat: MemoizeOption --------- Co-authored-by: Sojin Park <raon0211@toss.im>
27 lines
694 B
TypeScript
27 lines
694 B
TypeScript
import { bench, describe } from 'vitest';
|
|
import { memoize } from 'es-toolkit';
|
|
import { memoize as lodashMemoize } from 'lodash';
|
|
|
|
describe('memoize', () => {
|
|
const object = { a: 1, b: 2, c: 3 };
|
|
const other = { d: 4, e: 5, f: 6 };
|
|
const values = (args: object) => {
|
|
return Object.values(args);
|
|
};
|
|
bench('es-toolkit/memoize', () => {
|
|
const memoized = memoize(values);
|
|
memoized(object);
|
|
memoized(object); // cached
|
|
memoized(other);
|
|
memoized(other); // cached
|
|
});
|
|
|
|
bench('lodash/memoize', () => {
|
|
const memoized = lodashMemoize(values);
|
|
memoized(object);
|
|
memoized(object); // cached
|
|
memoized(other);
|
|
memoized(other); // cached
|
|
});
|
|
});
|