node/benchmark/process/getActiveResourcesInfo.js
Darshan Sen e35e893d26
src: speed up process.getActiveResourcesInfo()
This change reduces the number of calls that were crossing the JS-C++
boundary to 1 and also removes the need for calling Array::New()
multiple times internally and ArrayPrototypeConcat-ing the results
later on, thus improving performance.

Refs: https://github.com/nodejs/node/pull/44445#pullrequestreview-1220052837
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/46014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-01-03 10:36:25 +00:00

46 lines
991 B
JavaScript

'use strict';
const { createBenchmark } = require('../common.js');
const { connect, createServer } = require('net');
const { open } = require('fs');
const bench = createBenchmark(main, {
handlesCount: [1e4],
requestsCount: [1e4],
timeoutsCount: [1e4],
immediatesCount: [1e4],
n: [1e5],
});
function main({ handlesCount, requestsCount, timeoutsCount, immediatesCount, n }) {
const server = createServer().listen();
const clients = [];
for (let i = 0; i < handlesCount; i++) {
clients.push(connect({ port: server.address().port }));
}
for (let i = 0; i < requestsCount; i++) {
open(__filename, 'r', () => {});
}
for (let i = 0; i < timeoutsCount; ++i) {
setTimeout(() => {}, 1);
}
for (let i = 0; i < immediatesCount; ++i) {
setImmediate(() => {});
}
bench.start();
for (let i = 0; i < n; ++i) {
process.getActiveResourcesInfo();
}
bench.end(n);
for (const client of clients) {
client.destroy();
}
server.close();
}