es-toolkit/benchmarks/performance/memoize.bench.ts
novo 3cb5c804e1
feat(memoize): Add memoize (#208)
* 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>
2024-08-15 21:24:20 +09:00

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
});
});