-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-empty-object.mjs
34 lines (30 loc) · 980 Bytes
/
is-empty-object.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import _ from 'lodash'
import { isEmpty } from 'rambda'
import { bench, group, run } from 'tatami-ng'
import { generateRandomObject } from './benchmark-utils.mjs'
const object = generateRandomObject()
group(`Is empty object with ${Object.keys(object).length} keys`, () => {
bench('Reflect keys', (obj = object) => {
return obj?.constructor === Object && Reflect.ownKeys(obj).length === 0
})
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
})
bench('Object keys', (obj = object) => {
return obj?.constructor === Object && Object.keys(obj).length === 0
})
bench('lodash isEmpty', (obj = object) => {
_.isEmpty(obj)
})
bench('rambda isEmpty', (obj = object) => {
isEmpty(obj)
})
})
await run({
units: true,
})