Commit | Line | Data |
---|---|---|
6dce9ba7 | 1 | /* eslint-disable no-unused-vars */ |
f522d7b9 | 2 | import Benchmark from 'benny' |
f522d7b9 | 3 | import deepClone from 'deep-clone' |
0c01f51c JB |
4 | import clone from 'just-clone' |
5 | import _ from 'lodash' | |
6 | ||
95d31631 | 7 | import { generateRandomObject } from './benchmark-utils.mjs' |
6dce9ba7 | 8 | |
8e1fbc06 | 9 | const object = generateRandomObject() |
6dce9ba7 JB |
10 | |
11 | Benchmark.suite( | |
8e1fbc06 | 12 | `Deep clone object with ${Object.keys(object).length} keys`, |
5b907dbf | 13 | Benchmark.add('JSON stringify/parse', (obj = object) => { |
896570f7 | 14 | const objCloned = JSON.parse(JSON.stringify(obj)) |
6dce9ba7 | 15 | }), |
5b907dbf | 16 | Benchmark.add('structuredClone', (obj = object) => { |
896570f7 | 17 | const objCloned = structuredClone(obj) |
6dce9ba7 | 18 | }), |
5b907dbf | 19 | Benchmark.add('lodash cloneDeep', (obj = object) => { |
896570f7 | 20 | const objCloned = _.cloneDeep(obj) |
6dce9ba7 | 21 | }), |
5b907dbf | 22 | Benchmark.add('just-clone', (obj = object) => { |
896570f7 | 23 | const objCloned = clone(obj) |
a9aa1456 | 24 | }), |
f522d7b9 | 25 | Benchmark.add('deep-clone', (obj = object) => { |
896570f7 | 26 | const objCloned = deepClone(obj) |
f522d7b9 | 27 | }), |
6dce9ba7 JB |
28 | Benchmark.cycle(), |
29 | Benchmark.complete(), | |
30 | Benchmark.save({ | |
57f62217 | 31 | file: 'deep-clone-object', |
6dce9ba7 JB |
32 | format: 'json', |
33 | details: true | |
34 | }), | |
35 | Benchmark.save({ | |
57f62217 | 36 | file: 'deep-clone-object', |
6dce9ba7 JB |
37 | format: 'chart.html', |
38 | details: true | |
39 | }), | |
40 | Benchmark.save({ | |
57f62217 | 41 | file: 'deep-clone-object', |
6dce9ba7 JB |
42 | format: 'table.html', |
43 | details: true | |
44 | }) | |
4aa2893a | 45 | ).catch(console.error) |