Commit | Line | Data |
---|---|---|
6dce9ba7 JB |
1 | /* eslint-disable no-unused-vars */ |
2 | const Benchmark = require('benny') | |
5b907dbf | 3 | const { generateRandomObject } = require('./benchmark-utils') |
6dce9ba7 JB |
4 | const _ = require('lodash') |
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 | }) | |
36 | ) |