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