Commit | Line | Data |
---|---|---|
b64305b2 JB |
1 | const Benchmark = require('benny') |
2 | ||
3 | const emptyLiteral = {} | |
4 | ||
5 | Benchmark.suite( | |
6 | 'Empty object', | |
7 | Benchmark.add('Reflect keys', (obj = emptyLiteral) => { | |
8 | return Reflect.ownKeys(obj).length === 0 && obj.constructor === Object | |
9 | }), | |
10 | Benchmark.add('Keys iteration ', (obj = emptyLiteral) => { | |
11 | if (obj.constructor !== Object) return false | |
12 | // Iterates over the keys of an object, if | |
13 | // any exist, return false. | |
14 | // eslint-disable-next-line no-unreachable-loop | |
15 | for (const _ in obj) return false | |
16 | return true | |
17 | }), | |
18 | Benchmark.add('Object keys', (obj = emptyLiteral) => { | |
19 | return obj.constructor === Object && !Object.keys(obj).length | |
20 | }), | |
21 | Benchmark.cycle(), | |
22 | Benchmark.complete(), | |
23 | Benchmark.save({ | |
24 | file: 'empty-object', | |
25 | format: 'json', | |
26 | details: true | |
27 | }), | |
28 | Benchmark.save({ | |
29 | file: 'empty-object', | |
30 | format: 'chart.html', | |
31 | details: true | |
32 | }), | |
33 | Benchmark.save({ | |
34 | file: 'empty-object', | |
35 | format: 'table.html', | |
36 | details: true | |
37 | }) | |
38 | ) |