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