1 const Benchmark
= require('benny')
2 const { generateRandomObject
} = require('./benchmark-utils')
4 const object
= generateRandomObject()
7 `Is empty object with ${Object.keys(object).length} keys`,
8 Benchmark
.add('Reflect keys', (obj
= object
) => {
9 return obj
?.constructor === Object
&& Reflect
.ownKeys(obj
).length
=== 0
11 Benchmark
.add('Keys iteration', (obj
= object
) => {
12 if (obj
?.constructor !== Object
) return false
13 // Iterates over the keys of an object, if
14 // any exist, return false.
15 // eslint-disable-next-line no-unreachable-loop
16 for (const _
in obj
) return false
19 Benchmark
.add('Object keys', (obj
= object
) => {
20 return obj
?.constructor === Object
&& Object
.keys(obj
).length
=== 0
25 file
: 'is-empty-object',
30 file
: 'is-empty-object',
35 file
: 'is-empty-object',