build: bump volta node version
[benchmarks-js.git] / deep-clone-object.mjs
1 /* eslint-disable no-unused-vars */
2 import Benchmark from 'benny'
3 import deepClone from 'deep-clone'
4 import clone from 'just-clone'
5 import _ from 'lodash'
6
7 import { generateRandomObject } from './benchmark-utils.mjs'
8
9 const object = generateRandomObject()
10
11 Benchmark.suite(
12 `Deep clone object with ${Object.keys(object).length} keys`,
13 Benchmark.add('JSON stringify/parse', (obj = object) => {
14 const objCloned = JSON.parse(JSON.stringify(obj))
15 }),
16 Benchmark.add('structuredClone', (obj = object) => {
17 const objCloned = structuredClone(obj)
18 }),
19 Benchmark.add('lodash cloneDeep', (obj = object) => {
20 const objCloned = _.cloneDeep(obj)
21 }),
22 Benchmark.add('just-clone', (obj = object) => {
23 const objCloned = clone(obj)
24 }),
25 Benchmark.add('deep-clone', (obj = object) => {
26 const objCloned = deepClone(obj)
27 }),
28 Benchmark.cycle(),
29 Benchmark.complete(),
30 Benchmark.save({
31 file: 'deep-clone-object',
32 format: 'json',
33 details: true
34 }),
35 Benchmark.save({
36 file: 'deep-clone-object',
37 format: 'chart.html',
38 details: true
39 }),
40 Benchmark.save({
41 file: 'deep-clone-object',
42 format: 'table.html',
43 details: true
44 })
45 ).catch(console.error)