1 /* eslint-disable no-unused-vars */
2 const Benchmark
= require('benny')
3 const { generateRandomInteger
} = require('./benchmark-utils')
4 const _
= require('lodash')
6 const size
= generateRandomInteger(500)
8 for (let i
= 0; i
< size
; i
++) {
9 testObject
[i
.toString()] = i
13 `Clone object with ${size} keys`,
14 Benchmark
.add('structuredClone', (obj
= testObject
) => {
15 const objClone
= structuredClone(obj
)
17 Benchmark
.add('Spread', (obj
= testObject
) => {
18 const objClone
= { ...obj
}
20 Benchmark
.add('Object assign', (obj
= testObject
) => {
21 const objClone
= Object
.assign({}, obj
)
23 Benchmark
.add('JSON stringify/parse', (obj
= testObject
) => {
24 const objClone
= JSON
.parse(JSON
.stringify(obj
))
26 Benchmark
.add('lodash clone', (obj
= testObject
) => {
27 const objClone
= _
.clone(obj
)
29 Benchmark
.add('lodash deep clone', (obj
= testObject
) => {
30 const objClone
= _
.cloneDeep(obj
)