X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=deep-clone-object.js;h=0f480c424263664a2e02ab3d8663a9bb87c65bf6;hb=38acce1ce538dd398196b8ab7834d55938d4fde7;hp=de345fcafd594693740809f1335ea530518c72bf;hpb=57f622172596f25733fe81c176f8935752d2aab9;p=benchmarks-js.git diff --git a/deep-clone-object.js b/deep-clone-object.js index de345fc..0f480c4 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 _ = require('lodash') const clone = require('just-clone') +const { generateRandomObject } = require('./benchmark-utils') -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(), @@ -41,4 +37,6 @@ Benchmark.suite( format: 'table.html', details: true }) -) +).catch(err => { + console.error(err) +})