Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: benchmarking impacts of async hooks on promises #31188

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
}