Commit | Line | Data |
---|---|---|
7e861288 | 1 | const Benchmark = require('benny') |
ed2968f2 | 2 | |
e9bfc28e JB |
3 | /** |
4 | * | |
5 | */ | |
ed2968f2 | 6 | function promise () { |
7e861288 JB |
7 | return new Promise(resolve => { |
8 | resolve() | |
9 | }) | |
ed2968f2 JB |
10 | } |
11 | ||
e9bfc28e JB |
12 | /** |
13 | * | |
14 | */ | |
ed2968f2 | 15 | async function asyncFunction () { |
ce26b710 | 16 | return await promise() |
ed2968f2 JB |
17 | } |
18 | ||
7e861288 JB |
19 | Benchmark.suite( |
20 | 'Promise handling', | |
21 | Benchmark.add('await promise', async () => { | |
ed2968f2 | 22 | await asyncFunction() |
7e861288 JB |
23 | }), |
24 | Benchmark.add('promise', () => { | |
ed2968f2 | 25 | asyncFunction() |
7e861288 JB |
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 | |
ed2968f2 | 43 | }) |
7e861288 | 44 | ) |