X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=is-empty-object.mjs;h=842ae4a9ec812ee95e8f4e94e2445809e51f2305;hb=HEAD;hp=f718ada861751e905e11756ff83d79d5aacc834f;hpb=48f5216deed3bc4d9a64e81822fe8d6bd5c5cdcd;p=benchmarks-js.git diff --git a/is-empty-object.mjs b/is-empty-object.mjs index f718ada..45ac8e3 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) => { + _.isEmpty(obj) + }) + bench('rambda isEmpty', (obj = object) => { + isEmpty(obj) + }) +}) + +await run({ + units: true, })