2017-01-03 00:37:26 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const Writable = require('stream').Writable;
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2019-11-29 02:04:46 +01:00
|
|
|
n: [2e6],
|
|
|
|
sync: ['yes', 'no']
|
2017-01-03 00:37:26 +01:00
|
|
|
});
|
|
|
|
|
2019-11-29 02:04:46 +01:00
|
|
|
function main({ n, sync }) {
|
2017-01-03 00:37:26 +01:00
|
|
|
const b = Buffer.allocUnsafe(1024);
|
|
|
|
const s = new Writable();
|
2019-11-29 02:04:46 +01:00
|
|
|
sync = sync === 'yes';
|
2017-01-03 00:37:26 +01:00
|
|
|
s._write = function(chunk, encoding, cb) {
|
2019-11-29 02:04:46 +01:00
|
|
|
if (sync)
|
|
|
|
cb();
|
|
|
|
else
|
|
|
|
process.nextTick(cb);
|
2017-01-03 00:37:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bench.start();
|
2019-12-15 13:44:15 +01:00
|
|
|
|
|
|
|
let k = 0;
|
|
|
|
function run() {
|
|
|
|
while (k++ < n && s.write(b));
|
|
|
|
if (k >= n)
|
|
|
|
bench.end(n);
|
2017-01-03 00:37:26 +01:00
|
|
|
}
|
2019-12-15 13:44:15 +01:00
|
|
|
s.on('drain', run);
|
|
|
|
run();
|
2017-01-03 00:37:26 +01:00
|
|
|
}
|