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