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')
7 const size
= generateRandomInteger(500)
9 for (let i
= 0; i
< size
; i
++) {
10 testObject
[i
.toString()] = i
14 `Clone object with ${size} keys`,
15 Benchmark
.add('structuredClone', (obj
= testObject
) => {
16 const objClone
= structuredClone(obj
)
18 Benchmark
.add('Spread', (obj
= testObject
) => {
19 const objClone
= { ...obj
}
21 Benchmark
.add('Object assign', (obj
= testObject
) => {
22 const objClone
= Object
.assign({}, obj
)
24 Benchmark
.add('JSON stringify/parse', (obj
= testObject
) => {
25 const objClone
= JSON
.parse(JSON
.stringify(obj
))
27 Benchmark
.add('lodash clone', (obj
= testObject
) => {
28 const objClone
= _
.clone(obj
)
30 Benchmark
.add('lodash deep clone', (obj
= testObject
) => {
31 const objClone
= _
.cloneDeep(obj
)
33 Benchmark
.add('just-clone', (obj
= testObject
) => {
34 const objClone
= clone(obj
)