Skip to content

Commit

Permalink
benchmark: benchmarking impacts of async hooks on promises
Browse files Browse the repository at this point in the history
PR-URL: #31188
Refs: nodejs/diagnostics#124
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
legendecas authored and Trott committed Jan 8, 2020
1 parent 607be0c commit b3b0ae5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
18 changes: 9 additions & 9 deletions benchmark/async_hooks/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function main({ asyncHooks, connections }) {
}
}
const server = require('../fixtures/simple-http-server.js')
.listen(common.PORT)
.on('listening', () => {
const path = '/buffer/4/4/normal/1';
.listen(common.PORT)
.on('listening', () => {
const path = '/buffer/4/4/normal/1';

bench.http({
connections,
path,
}, () => {
server.close();
bench.http({
connections,
path,
}, () => {
server.close();
});
});
});
}
30 changes: 30 additions & 0 deletions benchmark/async_hooks/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const common = require('../common.js');
const { createHook } = require('async_hooks');

const bench = common.createBenchmark(main, {
n: [1e6],
asyncHooks: [
'enabled',
'disabled',
]
});

async function run(n) {
for (let i = 0; i < n; i++) {
await new Promise((resolve) => resolve())
.then(() => { throw new Error('foobar'); })
.catch((e) => e);
}
}

function main({ n, asyncHooks }) {
const hook = createHook({ promiseResolve() {} });
if (asyncHooks !== 'disabled') {
hook.enable();
}
bench.start();
run(n).then(() => {
bench.end(n);
});
}

0 comments on commit b3b0ae5

Please sign in to comment.