X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=deep-clone-object.js;h=ed308e9cd944187ed06946b2774b2fdac8666a02;hb=05a028289a08e96f12870f3c6c7df13d78f87c99;hp=de345fcafd594693740809f1335ea530518c72bf;hpb=57f622172596f25733fe81c176f8935752d2aab9;p=benchmarks-js.git diff --git a/deep-clone-object.js b/deep-clone-object.js index de345fc..ed308e9 100644 --- a/deep-clone-object.js +++ b/deep-clone-object.js @@ -1,27 +1,23 @@ /* eslint-disable no-unused-vars */ const Benchmark = require('benny') -const { generateRandomInteger } = require('./benchmark-utils') +const { generateRandomObject } = require('./benchmark-utils') const _ = require('lodash') const clone = require('just-clone') -const size = generateRandomInteger(500) -const testObject = {} -for (let i = 0; i < size; i++) { - testObject[i.toString()] = i -} +const object = generateRandomObject() Benchmark.suite( - `Deep clone object with ${size} keys`, - Benchmark.add('JSON stringify/parse', (obj = testObject) => { + `Deep clone object with ${Object.keys(object).length} keys`, + Benchmark.add('JSON stringify/parse', (obj = object) => { const objClone = JSON.parse(JSON.stringify(obj)) }), - Benchmark.add('structuredClone', (obj = testObject) => { + Benchmark.add('structuredClone', (obj = object) => { const objClone = structuredClone(obj) }), - Benchmark.add('lodash cloneDeep', (obj = testObject) => { + Benchmark.add('lodash cloneDeep', (obj = object) => { const objClone = _.cloneDeep(obj) }), - Benchmark.add('just-clone', (obj = testObject) => { + Benchmark.add('just-clone', (obj = object) => { const objClone = clone(obj) }), Benchmark.cycle(),