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