build: bump volta node version
[benchmarks-js.git] / is-empty-object.mjs
1 import _ from 'lodash'
2 import { isEmpty } from 'rambda'
3 import { bench, group, run } from 'tatami-ng'
4
5 import { generateRandomObject } from './benchmark-utils.mjs'
6
7 const object = generateRandomObject()
8
9 group(`Is empty object with ${Object.keys(object).length} keys`, () => {
10 bench('Reflect keys', (obj = object) => {
11 return obj?.constructor === Object && Reflect.ownKeys(obj).length === 0
12 })
13 bench('Keys iteration', (obj = object) => {
14 if (obj?.constructor !== Object) return false
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
20 })
21 bench('Object keys', (obj = object) => {
22 return obj?.constructor === Object && Object.keys(obj).length === 0
23 })
24 bench('lodash isEmpty', (obj = object) => {
25 _.isEmpty(obj)
26 })
27 bench('rambda isEmpty', (obj = object) => {
28 isEmpty(obj)
29 })
30 })
31
32 await run({
33 units: true
34 })