Commit | Line | Data |
---|---|---|
f522d7b9 | 1 | import Benchmark from 'benny' |
ed2968f2 | 2 | |
e9bfc28e JB |
3 | /** |
4 | * | |
5 | */ | |
bcd364e0 JB |
6 | async function asyncFunction () { |
7 | await new Promise(resolve => { | |
7e861288 JB |
8 | resolve() |
9 | }) | |
ed2968f2 JB |
10 | } |
11 | ||
7e861288 JB |
12 | Benchmark.suite( |
13 | 'Promise handling', | |
14 | Benchmark.add('await promise', async () => { | |
57f62217 JB |
15 | try { |
16 | return await asyncFunction() | |
17 | } catch (e) { | |
18 | console.error(e) | |
19 | } | |
7e861288 | 20 | }), |
57f62217 JB |
21 | Benchmark.add('promise with then().catch()', () => { |
22 | asyncFunction() | |
f913c68c | 23 | .then(r => { |
57f62217 JB |
24 | return r |
25 | }) | |
f913c68c | 26 | .catch(e => { |
57f62217 JB |
27 | console.error(e) |
28 | }) | |
29 | }), | |
1f89b386 JB |
30 | Benchmark.add('voided promise', () => { |
31 | // eslint-disable-next-line no-void | |
32 | void asyncFunction() | |
33 | }), | |
57f62217 | 34 | Benchmark.add('mishandled promise', () => { |
ed2968f2 | 35 | asyncFunction() |
7e861288 JB |
36 | }), |
37 | Benchmark.cycle(), | |
38 | Benchmark.complete(), | |
39 | Benchmark.save({ | |
40 | file: 'promise-handling', | |
41 | format: 'json', | |
42 | details: true | |
43 | }), | |
44 | Benchmark.save({ | |
45 | file: 'promise-handling', | |
46 | format: 'chart.html', | |
47 | details: true | |
48 | }), | |
49 | Benchmark.save({ | |
50 | file: 'promise-handling', | |
51 | format: 'table.html', | |
52 | details: true | |
ed2968f2 | 53 | }) |
f913c68c | 54 | ).catch(err => { |
4b16770a JB |
55 | console.error(err) |
56 | }) |