| 1 | const Benchmark = require('benchmark') |
| 2 | const { LIST_FORMATTER } = require('./benchmark-utils') |
| 3 | |
| 4 | const suite = new Benchmark.Suite() |
| 5 | |
| 6 | /** |
| 7 | * |
| 8 | */ |
| 9 | function promise () { |
| 10 | return new Promise() |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * |
| 15 | */ |
| 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 | ) |
| 34 | // eslint-disable-next-line no-process-exit |
| 35 | process.exit() |
| 36 | }) |
| 37 | .run() |