Move random generator inputs check at the right place
[benchmarks-js.git] / promise-handling.js
CommitLineData
ed2968f2
JB
1const Benchmark = require('benchmark')
2const { LIST_FORMATTER } = require('./benchmark-utils')
3
4const suite = new Benchmark.Suite()
5
e9bfc28e
JB
6/**
7 *
8 */
ed2968f2
JB
9function promise () {
10 return new Promise()
11}
12
e9bfc28e
JB
13/**
14 *
15 */
ed2968f2
JB
16async function asyncFunction () {
17 await promise()
18}
19
20suite
e2bfb549 21 .add('await promise', async () => {
ed2968f2
JB
22 await asyncFunction()
23 })
e2bfb549 24 .add('promise', () => {
ed2968f2
JB
25 asyncFunction()
26 })
e2bfb549 27 .on('cycle', event => {
ed2968f2
JB
28 console.log(event.target.toString())
29 })
30 .on('complete', function () {
31 console.log(
32 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name'))
33 )
7fd91296 34 // eslint-disable-next-line n/no-process-exit
ed2968f2
JB
35 process.exit()
36 })
37 .run()