Commit | Line | Data |
---|---|---|
ed2968f2 JB |
1 | const Benchmark = require('benchmark') |
2 | const { LIST_FORMATTER } = require('./benchmark-utils') | |
3 | ||
4 | const suite = new Benchmark.Suite() | |
5 | ||
6 | function promise () { | |
7 | return new Promise() | |
8 | } | |
9 | ||
10 | async function asyncFunction () { | |
11 | await promise() | |
12 | } | |
13 | ||
14 | suite | |
15 | .add('await promise', async function () { | |
16 | await asyncFunction() | |
17 | }) | |
18 | .add('promise', function () { | |
19 | asyncFunction() | |
20 | }) | |
21 | .on('cycle', function (event) { | |
22 | console.log(event.target.toString()) | |
23 | }) | |
24 | .on('complete', function () { | |
25 | console.log( | |
26 | 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) | |
27 | ) | |
28 | // eslint-disable-next-line no-process-exit | |
29 | process.exit() | |
30 | }) | |
31 | .run() |