build: bump volta pnpm version
[benchmarks-js.git] / promise-handling.mjs
CommitLineData
f522d7b9 1import Benchmark from 'benny'
ed2968f2 2
e9bfc28e
JB
3/**
4 *
5 */
bcd364e0
JB
6async function asyncFunction () {
7 await new Promise(resolve => {
7e861288
JB
8 resolve()
9 })
ed2968f2
JB
10}
11
7e861288
JB
12Benchmark.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 })
4aa2893a 26 .catch(console.error)
57f62217 27 }),
1f89b386
JB
28 Benchmark.add('voided promise', () => {
29 // eslint-disable-next-line no-void
30 void asyncFunction()
31 }),
57f62217 32 Benchmark.add('mishandled promise', () => {
ed2968f2 33 asyncFunction()
7e861288
JB
34 }),
35 Benchmark.cycle(),
36 Benchmark.complete(),
37 Benchmark.save({
38 file: 'promise-handling',
39 format: 'json',
40 details: true
41 }),
42 Benchmark.save({
43 file: 'promise-handling',
44 format: 'chart.html',
45 details: true
46 }),
47 Benchmark.save({
48 file: 'promise-handling',
49 format: 'table.html',
50 details: true
ed2968f2 51 })
4aa2893a 52).catch(console.error)