| 1 | /* eslint-disable no-unused-vars */ |
| 2 | const Benchmark = require('benny') |
| 3 | const { generateRandomObject } = require('./benchmark-utils') |
| 4 | const _ = require('lodash') |
| 5 | |
| 6 | const object = generateRandomObject() |
| 7 | |
| 8 | Benchmark.suite( |
| 9 | `Shallow clone object with ${Object.keys(object).length} keys`, |
| 10 | Benchmark.add('Spread', (obj = object) => { |
| 11 | const objClone = { ...obj } |
| 12 | }), |
| 13 | Benchmark.add('Object assign', (obj = object) => { |
| 14 | const objClone = Object.assign({}, obj) |
| 15 | }), |
| 16 | Benchmark.add('lodash clone', (obj = object) => { |
| 17 | const objClone = _.clone(obj) |
| 18 | }), |
| 19 | Benchmark.cycle(), |
| 20 | Benchmark.complete(), |
| 21 | Benchmark.save({ |
| 22 | file: 'shallow-clone-object', |
| 23 | format: 'json', |
| 24 | details: true |
| 25 | }), |
| 26 | Benchmark.save({ |
| 27 | file: 'shallow-clone-object', |
| 28 | format: 'chart.html', |
| 29 | details: true |
| 30 | }), |
| 31 | Benchmark.save({ |
| 32 | file: 'shallow-clone-object', |
| 33 | format: 'table.html', |
| 34 | details: true |
| 35 | }) |
| 36 | ) |