diff options
author | Stephen Belanger <stephen.belanger@datadoghq.com> | 2021-08-26 08:22:38 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-09-06 10:19:23 +0300 |
commit | 2343c394fba8436583a2646b63a20ab243c1a217 (patch) | |
tree | f0854b586286ea437ea4b1b0566e31d03de31b29 /benchmark | |
parent | ca9b781d20f4f4348904adcdedef0a70fbb69669 (diff) |
async_hooks: use resource stack for AsyncLocalStorage run
PR-URL: https://github.com/nodejs/node/pull/39890
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/async_hooks/async-local-storage-run.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/benchmark/async_hooks/async-local-storage-run.js b/benchmark/async_hooks/async-local-storage-run.js new file mode 100644 index 00000000000..d65abb7047b --- /dev/null +++ b/benchmark/async_hooks/async-local-storage-run.js @@ -0,0 +1,21 @@ +'use strict'; +const common = require('../common.js'); +const { AsyncLocalStorage } = require('async_hooks'); + +const bench = common.createBenchmark(main, { + n: [1e7] +}); + +async function run(store, n) { + for (let i = 0; i < n; i++) { + await new Promise((resolve) => store.run(i, resolve)); + } +} + +function main({ n }) { + const store = new AsyncLocalStorage(); + bench.start(); + run(store, n).then(() => { + bench.end(n); + }); +} |