mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Speed up Interface construction: - Hoist the history accessor property descriptors to module scope and define them with a single ObjectDefineProperties call, instead of allocating six closures and four descriptor objects per instance. - Stop assigning the history options onto the input stream. This avoids hidden class transitions on the user provided stream and no longer mutates it observably. - Only check process.env.TERM for a dumb terminal when the interface is in terminal mode. Reading process.env goes through the environment interceptor and is comparatively expensive, and _ttyWrite is never called when terminal is false. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/64585 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
27 lines
601 B
JavaScript
27 lines
601 B
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const readline = require('readline');
|
|
const { Readable, Writable } = require('stream');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e5],
|
|
terminal: [0, 1],
|
|
});
|
|
|
|
function main({ n, terminal }) {
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
const input = new Readable({ read() {} });
|
|
const output = new Writable({ write(chunk, encoding, callback) {
|
|
callback();
|
|
} });
|
|
const rl = readline.createInterface({
|
|
input,
|
|
output,
|
|
terminal: Boolean(terminal),
|
|
});
|
|
rl.close();
|
|
}
|
|
bench.end(n);
|
|
}
|