Add just-clone to cloning benchmark
[benchmarks-js.git] / deep-clone-object.js
1 /* eslint-disable no-unused-vars */
2 const Benchmark = require('benny')
3 const { generateRandomInteger } = require('./benchmark-utils')
4 const _ = require('lodash')
5 const clone = require('just-clone')
6
7 const size = generateRandomInteger(500)
8 const testObject = {}
9 for (let i = 0; i < size; i++) {
10 testObject[i.toString()] = i
11 }
12
13 Benchmark.suite(
14 `Deep clone object with ${size} keys`,
15 Benchmark.add('JSON stringify/parse', (obj = testObject) => {
16 const objClone = JSON.parse(JSON.stringify(obj))
17 }),
18 Benchmark.add('structuredClone', (obj = testObject) => {
19 const objClone = structuredClone(obj)
20 }),
21 Benchmark.add('lodash cloneDeep', (obj = testObject) => {
22 const objClone = _.cloneDeep(obj)
23 }),
24 Benchmark.add('just-clone', (obj = testObject) => {
25 const objClone = clone(obj)
26 }),
27 Benchmark.cycle(),
28 Benchmark.complete(),
29 Benchmark.save({
30 file: 'deep-clone-object',
31 format: 'json',
32 details: true
33 }),
34 Benchmark.save({
35 file: 'deep-clone-object',
36 format: 'chart.html',
37 details: true
38 }),
39 Benchmark.save({
40 file: 'deep-clone-object',
41 format: 'table.html',
42 details: true
43 })
44 )