es-toolkit/benchmarks/performance/cloneDeep.bench.ts
Dayong Lee bcc3e924fd
chore: move some of files to performance folder and change path of importing correctly (#375)
* Remove duplicated zipObjectDeep bench

* set: Move and import from compat

* cloneDeep: Move to benchmarks folder

* startCase: Move to benchmarks folder
2024-08-11 15:21:14 +09:00

34 lines
767 B
TypeScript

import { bench, describe } from 'vitest';
import { cloneDeep } from 'es-toolkit';
import { cloneDeep as lodashCloneDeep } from 'lodash';
const obj = {
number: 29,
string: 'es-toolkit',
boolean: true,
array: [1, 2, 3],
object: { a: 1, b: 'es-toolkit' },
date: new Date(),
regex: /abc/g,
nested: { a: [1, 2, 3], b: { c: 'es-toolkit' }, d: new Date() },
nested2: { a: { b: { c: { d: { e: { f: { g: 'es-toolkit' } } } } } } },
};
describe('cloneDeep', () => {
bench('es-toolkit/cloneDeep', () => {
cloneDeep(obj);
});
bench('lodash/cloneDeep', () => {
lodashCloneDeep(obj);
});
bench('node/JSON.parse', () => {
JSON.parse(JSON.stringify(obj));
});
bench('node/structuredClone', () => {
structuredClone(obj);
});
});