Merge pull request #71 from jerome-benoit/dependabot/npm_and_yarn/eslint-plugin-n...
[benchmarks-js.git] / shallow-clone-object.mjs
CommitLineData
6dce9ba7 1/* eslint-disable no-unused-vars */
f522d7b9
JB
2import Benchmark from 'benny'
3import _ from 'lodash'
95d31631 4import { generateRandomObject } from './benchmark-utils.mjs'
6dce9ba7 5
8e1fbc06 6const object = generateRandomObject()
6dce9ba7
JB
7
8Benchmark.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})