build: bump volta node version
[benchmarks-js.git] / is-empty-object.mjs
CommitLineData
ab9a08f3 1import _ from 'lodash'
ab9a08f3 2import { isEmpty } from 'rambda'
4676a95c 3import { bench, group, run } from 'tatami-ng'
0c01f51c 4
95d31631 5import { generateRandomObject } from './benchmark-utils.mjs'
b64305b2 6
8e1fbc06 7const object = generateRandomObject()
b64305b2 8
ab9a08f3
JB
9group(`Is empty object with ${Object.keys(object).length} keys`, () => {
10 bench('Reflect keys', (obj = object) => {
2d1206f1 11 return obj?.constructor === Object && Reflect.ownKeys(obj).length === 0
ab9a08f3
JB
12 })
13 bench('Keys iteration', (obj = object) => {
9d7eeee7 14 if (obj?.constructor !== Object) return false
b64305b2
JB
15 // Iterates over the keys of an object, if
16 // any exist, return false.
17 // eslint-disable-next-line no-unreachable-loop
18 for (const _ in obj) return false
19 return true
ab9a08f3
JB
20 })
21 bench('Object keys', (obj = object) => {
2d1206f1 22 return obj?.constructor === Object && Object.keys(obj).length === 0
b64305b2 23 })
ab9a08f3 24 bench('lodash isEmpty', (obj = object) => {
bf2f087f 25 _.isEmpty(obj)
ab9a08f3 26 })
78ccf400 27 bench('rambda isEmpty', (obj = object) => {
bf2f087f 28 isEmpty(obj)
ab9a08f3
JB
29 })
30})
31
32await run({
33 units: true
34})