diff options
author | Stephen Belanger <admin@stephenbelanger.com> | 2020-04-17 01:23:57 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-05-09 08:52:22 +0300 |
commit | 13c5a1629cd025ba560f34f6d3190b2f38d184d4 (patch) | |
tree | 69b199545b85d7d9d71fb7500e281a3e5ef88e33 /benchmark | |
parent | 023bcdeb2848186192d2d3cd7ac33ff911b9a9ce (diff) |
async_hooks: move PromiseHook handler to JS
This avoids the need to wrap every promise in an AsyncWrap and also
makes it easier to skip the machinery to track destroy events when
there's no destroy listener.
Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/32891
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/async_hooks/promises.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/benchmark/async_hooks/promises.js b/benchmark/async_hooks/promises.js index eb90ca0368e..5632a6901d6 100644 --- a/benchmark/async_hooks/promises.js +++ b/benchmark/async_hooks/promises.js @@ -2,10 +2,31 @@ const common = require('../common.js'); const { createHook } = require('async_hooks'); +let hook; +const tests = { + disabled() { + hook = createHook({ + promiseResolve() {} + }); + }, + enabled() { + hook = createHook({ + promiseResolve() {} + }).enable(); + }, + enabledWithDestroy() { + hook = createHook({ + promiseResolve() {}, + destroy() {} + }).enable(); + } +}; + const bench = common.createBenchmark(main, { n: [1e6], asyncHooks: [ 'enabled', + 'enabledWithDestroy', 'disabled', ] }); @@ -19,10 +40,8 @@ async function run(n) { } function main({ n, asyncHooks }) { - const hook = createHook({ promiseResolve() {} }); - if (asyncHooks !== 'disabled') { - hook.enable(); - } + if (hook) hook.disable(); + tests[asyncHooks](); bench.start(); run(n).then(() => { bench.end(n); |