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