Commit | Line | Data |
---|---|---|
6dce9ba7 JB |
1 | /* eslint-disable no-unused-vars */ |
2 | const Benchmark = require('benny') | |
3 | const { generateRandomInteger } = require('./benchmark-utils') | |
4 | const _ = require('lodash') | |
a9aa1456 | 5 | const clone = require('just-clone') |
6dce9ba7 JB |
6 | |
7 | const size = generateRandomInteger(500) | |
8 | const testObject = {} | |
9 | for (let i = 0; i < size; i++) { | |
10 | testObject[i.toString()] = i | |
11 | } | |
12 | ||
13 | Benchmark.suite( | |
57f62217 | 14 | `Deep clone object with ${size} keys`, |
6dce9ba7 JB |
15 | Benchmark.add('JSON stringify/parse', (obj = testObject) => { |
16 | const objClone = JSON.parse(JSON.stringify(obj)) | |
17 | }), | |
57f62217 JB |
18 | Benchmark.add('structuredClone', (obj = testObject) => { |
19 | const objClone = structuredClone(obj) | |
6dce9ba7 | 20 | }), |
57f62217 | 21 | Benchmark.add('lodash cloneDeep', (obj = testObject) => { |
6dce9ba7 JB |
22 | const objClone = _.cloneDeep(obj) |
23 | }), | |
a9aa1456 JB |
24 | Benchmark.add('just-clone', (obj = testObject) => { |
25 | const objClone = clone(obj) | |
26 | }), | |
6dce9ba7 JB |
27 | Benchmark.cycle(), |
28 | Benchmark.complete(), | |
29 | Benchmark.save({ | |
57f62217 | 30 | file: 'deep-clone-object', |
6dce9ba7 JB |
31 | format: 'json', |
32 | details: true | |
33 | }), | |
34 | Benchmark.save({ | |
57f62217 | 35 | file: 'deep-clone-object', |
6dce9ba7 JB |
36 | format: 'chart.html', |
37 | details: true | |
38 | }), | |
39 | Benchmark.save({ | |
57f62217 | 40 | file: 'deep-clone-object', |
6dce9ba7 JB |
41 | format: 'table.html', |
42 | details: true | |
43 | }) | |
44 | ) |