From: Jérôme Benoit Date: Mon, 26 Dec 2022 12:17:58 +0000 (+0100) Subject: Cleanup object generator API X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8e1fbc065cb9d9027c8fad951ff1a0d9960dbce5;p=benchmarks-js.git Cleanup object generator API Signed-off-by: Jérôme Benoit --- diff --git a/benchmark-utils.js b/benchmark-utils.js index 9c82d84..83d17ca 100644 --- a/benchmark-utils.js +++ b/benchmark-utils.js @@ -78,7 +78,7 @@ function generateRandomObject ( for (let i = 0; i < size; i++) { object[i.toString()] = numberGenerator(numberMax) } - return { object, size } + return object } /** diff --git a/deep-clone-object.js b/deep-clone-object.js index e1d8b1c..ed308e9 100644 --- a/deep-clone-object.js +++ b/deep-clone-object.js @@ -4,10 +4,10 @@ const { generateRandomObject } = require('./benchmark-utils') const _ = require('lodash') const clone = require('just-clone') -const { object, size } = generateRandomObject() +const object = generateRandomObject() Benchmark.suite( - `Deep clone object with ${size} keys`, + `Deep clone object with ${Object.keys(object).length} keys`, Benchmark.add('JSON stringify/parse', (obj = object) => { const objClone = JSON.parse(JSON.stringify(obj)) }), diff --git a/is-empty-object.js b/is-empty-object.js index b1f4d76..394555b 100644 --- a/is-empty-object.js +++ b/is-empty-object.js @@ -1,10 +1,10 @@ const Benchmark = require('benny') const { generateRandomObject } = require('./benchmark-utils') -const { object, size } = generateRandomObject() +const object = generateRandomObject() Benchmark.suite( - `Is empty object with ${size} keys`, + `Is empty object with ${Object.keys(object).length} keys`, Benchmark.add('Reflect keys', (obj = object) => { return obj?.constructor === Object && Reflect.ownKeys(obj).length === 0 }), diff --git a/shallow-clone-object.js b/shallow-clone-object.js index 18c396d..7ccc541 100644 --- a/shallow-clone-object.js +++ b/shallow-clone-object.js @@ -3,10 +3,10 @@ const Benchmark = require('benny') const { generateRandomObject } = require('./benchmark-utils') const _ = require('lodash') -const { object, size } = generateRandomObject() +const object = generateRandomObject() Benchmark.suite( - `Shallow clone object with ${size} keys`, + `Shallow clone object with ${Object.keys(object).length} keys`, Benchmark.add('Spread', (obj = object) => { const objClone = { ...obj } }),