build: bump volta node version
[benchmarks-js.git] / is-empty-object.mjs
CommitLineData
ab9a08f3
JB
1import _ from 'lodash'
2import { bench, group, run } from 'mitata'
3import { isEmpty } from 'rambda'
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
JB
24 bench('lodash isEmpty', (obj = object) => {
25 return _.isEmpty(obj)
26 })
78ccf400 27 bench('rambda isEmpty', (obj = object) => {
ab9a08f3
JB
28 return isEmpty(obj)
29 })
30})
31
32await run({
33 units: true
34})