0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/async_hooks/gc-tracking.js
Ruben Bridgewater 1b6cb94761
benchmark: refactor
PR-URL: https://github.com/nodejs/node/pull/18320
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-02-01 10:49:04 +01:00

45 lines
876 B
JavaScript

'use strict';
const common = require('../common.js');
const { AsyncResource } = require('async_hooks');
const bench = common.createBenchmark(main, {
n: [1e6],
method: [
'trackingEnabled',
'trackingDisabled',
]
}, {
flags: ['--expose-gc']
});
function endAfterGC(n) {
setImmediate(() => {
global.gc();
setImmediate(() => {
bench.end(n);
});
});
}
function main({ n, method }) {
var i;
switch (method) {
case 'trackingEnabled':
bench.start();
for (i = 0; i < n; i++) {
new AsyncResource('foobar');
}
endAfterGC(n);
break;
case 'trackingDisabled':
bench.start();
for (i = 0; i < n; i++) {
new AsyncResource('foobar', { requireManualDestroy: true });
}
endAfterGC(n);
break;
default:
throw new Error(`Unsupported method "${method}"`);
}
}