X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=shallow-clone-object.js;h=f8e193b65e701a7d91294cfa6bf973cd7d6b696d;hb=e1d7dc48b4eb61edc0e186f6b473c795b30cd6e6;hp=131b5e974842c7217657ebd409cd9f6d618a31ef;hpb=57f622172596f25733fe81c176f8935752d2aab9;p=benchmarks-js.git diff --git a/shallow-clone-object.js b/shallow-clone-object.js index 131b5e9..f8e193b 100644 --- a/shallow-clone-object.js +++ b/shallow-clone-object.js @@ -1,23 +1,19 @@ /* eslint-disable no-unused-vars */ const Benchmark = require('benny') -const { generateRandomInteger } = require('./benchmark-utils') const _ = require('lodash') +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( - `Shallow clone object with ${size} keys`, - Benchmark.add('Spread', (obj = testObject) => { + `Shallow clone object with ${Object.keys(object).length} keys`, + Benchmark.add('Spread', (obj = object) => { const objClone = { ...obj } }), - Benchmark.add('Object assign', (obj = testObject) => { + Benchmark.add('Object assign', (obj = object) => { const objClone = Object.assign({}, obj) }), - Benchmark.add('lodash clone', (obj = testObject) => { + Benchmark.add('lodash clone', (obj = object) => { const objClone = _.clone(obj) }), Benchmark.cycle(), @@ -37,4 +33,6 @@ Benchmark.suite( format: 'table.html', details: true }) -) +).catch(err => { + console.error(err) +})