X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=is-empty-object.mjs;h=bc7faf9610011ba114819e7dfa0f000a0520f768;hb=ab9a08f3b8fdd43f8714e90652028621849f9f58;hp=f110816aae6d83ad6c9de6beae624ba175ff2ba3;hpb=1b4e2f913afc4f5dfed823720d89dde05d23d184;p=benchmarks-js.git diff --git a/is-empty-object.mjs b/is-empty-object.mjs index f110816..bc7faf9 100644 --- a/is-empty-object.mjs +++ b/is-empty-object.mjs @@ -1,40 +1,34 @@ -import Benchmark from 'benny' +import _ from 'lodash' +import { bench, group, run } from 'mitata' +import { isEmpty } from 'rambda' 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(console.error) + bench('lodash isEmpty', (obj = object) => { + return _.isEmpty(obj) + }) + bench('rambda is Empty', (obj = object) => { + return isEmpty(obj) + }) +}) + +await run({ + units: true +})