2022-12-22 00:09:43 +08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const {
|
|
|
|
ReadableStream,
|
|
|
|
WritableStream,
|
|
|
|
} = require('node:stream/web');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2023-09-14 03:44:44 +08:00
|
|
|
n: [5e5],
|
2022-12-22 00:09:43 +08:00
|
|
|
highWaterMarkR: [512, 1024, 2048, 4096],
|
|
|
|
highWaterMarkW: [512, 1024, 2048, 4096],
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async function main({ n, highWaterMarkR, highWaterMarkW }) {
|
|
|
|
const b = Buffer.alloc(1024);
|
|
|
|
let i = 0;
|
|
|
|
const rs = new ReadableStream({
|
|
|
|
highWaterMark: highWaterMarkR,
|
|
|
|
pull: function(controller) {
|
2023-09-08 20:53:40 +08:00
|
|
|
if (i++ < n) {
|
2022-12-22 00:09:43 +08:00
|
|
|
controller.enqueue(b);
|
|
|
|
} else {
|
|
|
|
controller.close();
|
|
|
|
}
|
2023-01-30 02:13:35 +08:00
|
|
|
},
|
2022-12-22 00:09:43 +08:00
|
|
|
});
|
|
|
|
const ws = new WritableStream({
|
|
|
|
highWaterMark: highWaterMarkW,
|
|
|
|
write(chunk, controller) {},
|
|
|
|
close() { bench.end(n); },
|
|
|
|
});
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
rs.pipeTo(ws);
|
|
|
|
}
|