mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
7d258db1d7
PR-URL: https://github.com/nodejs/node/pull/51866 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Raz Luvaton <rluvaton@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const { Writable } = require('stream');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [50e6],
|
|
kind: ['write', 'object-mode', 'writev'],
|
|
});
|
|
const ABC = new Uint8Array([0x41, 0x42, 0x43]);
|
|
|
|
function main({ n, kind }) {
|
|
switch (kind) {
|
|
case 'write': {
|
|
bench.start();
|
|
const wr = new Writable({
|
|
write(chunk, encoding, cb) {
|
|
cb();
|
|
},
|
|
});
|
|
for (let i = 0; i < n; ++i) wr.write(ABC);
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
|
|
case 'object-mode': {
|
|
bench.start();
|
|
const wr = new Writable({
|
|
objectMode: true,
|
|
write(chunk, encoding, cb) {
|
|
cb();
|
|
},
|
|
});
|
|
for (let i = 0; i < n; ++i) wr.write(ABC);
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
case 'writev': {
|
|
bench.start();
|
|
const wr = new Writable({
|
|
writev(chunks, cb) {
|
|
cb();
|
|
},
|
|
});
|
|
for (let i = 0; i < n; ++i) wr.write(ABC);
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
default:
|
|
throw new Error('Invalid kind');
|
|
}
|
|
}
|