mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
8ed44ff1c4
For tests / benchmarks that are creating Buffer instances for any reason other than to test Buffer constructor, use the new Buffer.alloc/Buffer.from API instead of the deprecated API. PR-URL: https://github.com/nodejs/node/pull/18980 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
25 lines
448 B
JavaScript
25 lines
448 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { Readable, Writable } = require('stream');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [5e6]
|
|
});
|
|
|
|
function main({ n }) {
|
|
const b = Buffer.alloc(1024);
|
|
const r = new Readable();
|
|
const w = new Writable();
|
|
|
|
var i = 0;
|
|
|
|
r._read = () => r.push(i++ === n ? null : b);
|
|
w._write = (data, enc, cb) => cb();
|
|
|
|
bench.start();
|
|
|
|
r.pipe(w);
|
|
w.on('finish', () => bench.end(n));
|
|
}
|