Merge pull request #124 from jerome-benoit/dependabot/npm_and_yarn/commitlint/cli...
[benchmarks-js.git] / shallow-clone-object.mjs
1 /* eslint-disable no-unused-vars */
2 import Benchmark from 'benny'
3 import _ from 'lodash'
4 import { generateRandomObject } from './benchmark-utils.mjs'
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 ).catch(console.error)