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 | ||
e9bfc28e JB |
6 | /** |
7 | * | |
8 | */ | |
ed2968f2 JB |
9 | function promise () { |
10 | return new Promise() | |
11 | } | |
12 | ||
e9bfc28e JB |
13 | /** |
14 | * | |
15 | */ | |
ed2968f2 JB |
16 | async function asyncFunction () { |
17 | await promise() | |
18 | } | |
19 | ||
20 | suite | |
21 | .add('await promise', async function () { | |
22 | await asyncFunction() | |
23 | }) | |
24 | .add('promise', function () { | |
25 | asyncFunction() | |
26 | }) | |
27 | .on('cycle', function (event) { | |
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() |