build(deps-dev): apply updates
[benchmarks-js.git] / deep-clone-object.js
index de345fcafd594693740809f1335ea530518c72bf..0f480c424263664a2e02ab3d8663a9bb87c65bf6 100644 (file)
@@ -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)
+})