| 1 | const Benchmark = require('benny') |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | */ |
| 6 | function promise () { |
| 7 | return new Promise(resolve => { |
| 8 | resolve() |
| 9 | }) |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | */ |
| 15 | async function asyncFunction () { |
| 16 | return await promise() |
| 17 | } |
| 18 | |
| 19 | Benchmark.suite( |
| 20 | 'Promise handling', |
| 21 | Benchmark.add('await promise', async () => { |
| 22 | await asyncFunction() |
| 23 | }), |
| 24 | Benchmark.add('promise', () => { |
| 25 | asyncFunction() |
| 26 | }), |
| 27 | Benchmark.cycle(), |
| 28 | Benchmark.complete(), |
| 29 | Benchmark.save({ |
| 30 | file: 'promise-handling', |
| 31 | format: 'json', |
| 32 | details: true |
| 33 | }), |
| 34 | Benchmark.save({ |
| 35 | file: 'promise-handling', |
| 36 | format: 'chart.html', |
| 37 | details: true |
| 38 | }), |
| 39 | Benchmark.save({ |
| 40 | file: 'promise-handling', |
| 41 | format: 'table.html', |
| 42 | details: true |
| 43 | }) |
| 44 | ) |