mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
997c47fba7
PR-URL: https://github.com/nodejs/node/pull/46424 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const { createHook, AsyncResource } = require('async_hooks');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e6],
|
|
method: [
|
|
'trackingEnabled',
|
|
'trackingEnabledWithDestroyHook',
|
|
'trackingDisabled',
|
|
],
|
|
}, {
|
|
flags: ['--expose-gc'],
|
|
});
|
|
|
|
function endAfterGC(n) {
|
|
setImmediate(() => {
|
|
global.gc();
|
|
setImmediate(() => {
|
|
bench.end(n);
|
|
});
|
|
});
|
|
}
|
|
|
|
function main({ n, method }) {
|
|
switch (method) {
|
|
case 'trackingEnabled':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
new AsyncResource('foobar');
|
|
}
|
|
endAfterGC(n);
|
|
break;
|
|
case 'trackingEnabledWithDestroyHook':
|
|
createHook({ destroy: () => {} }).enable();
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
new AsyncResource('foobar');
|
|
}
|
|
endAfterGC(n);
|
|
break;
|
|
case 'trackingDisabled':
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
new AsyncResource('foobar', { requireManualDestroy: true });
|
|
}
|
|
endAfterGC(n);
|
|
break;
|
|
default:
|
|
throw new Error(`Unsupported method "${method}"`);
|
|
}
|
|
}
|