X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=is-empty-object.mjs;h=2d788816db5f5fb3afdece0a6e34a0861c23e4c4;hb=393aec7bb42c04ec01250abc4b75bab0441cb693;hp=b4ba3cbb8f8faa8a4fbe61d930b29618c03513b3;hpb=95d31631e49a5a39e261745c31f526691dab5f81;p=benchmarks-js.git diff --git a/is-empty-object.mjs b/is-empty-object.mjs index b4ba3cb..2d78881 100644 --- a/is-empty-object.mjs +++ b/is-empty-object.mjs @@ -1,41 +1,34 @@ -import Benchmark from 'benny' +import _ from 'lodash' +import { isEmpty } from 'rambda' +import { bench, group, run } from 'tatami-ng' + import { generateRandomObject } from './benchmark-utils.mjs' const object = generateRandomObject() -Benchmark.suite( - `Is empty object with ${Object.keys(object).length} keys`, - Benchmark.add('Reflect keys', (obj = object) => { +group(`Is empty object with ${Object.keys(object).length} keys`, () => { + bench('Reflect keys', (obj = object) => { return obj?.constructor === Object && Reflect.ownKeys(obj).length === 0 - }), - Benchmark.add('Keys iteration', (obj = object) => { + }) + bench('Keys iteration', (obj = object) => { if (obj?.constructor !== Object) return false // Iterates over the keys of an object, if // any exist, return false. // eslint-disable-next-line no-unreachable-loop for (const _ in obj) return false return true - }), - Benchmark.add('Object keys', (obj = object) => { + }) + bench('Object keys', (obj = object) => { return obj?.constructor === Object && Object.keys(obj).length === 0 - }), - Benchmark.cycle(), - Benchmark.complete(), - Benchmark.save({ - file: 'is-empty-object', - format: 'json', - details: true - }), - Benchmark.save({ - file: 'is-empty-object', - format: 'chart.html', - details: true - }), - Benchmark.save({ - file: 'is-empty-object', - format: 'table.html', - details: true }) -).catch(err => { - console.error(err) + bench('lodash isEmpty', (obj = object) => { + return _.isEmpty(obj) + }) + bench('rambda isEmpty', (obj = object) => { + return isEmpty(obj) + }) +}) + +await run({ + units: true })