Skip to content

Commit 536d2ac

Browse files
committed
benchmark: add pipeTo sync source throughput case
1 parent 0fec292 commit 536d2ac

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

benchmark/streams/iter-throughput-pipeto.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const common = require('../common.js');
66
const { Readable, Writable, pipeline } = require('stream');
77

88
const bench = common.createBenchmark(main, {
9-
api: ['classic', 'webstream', 'iter', 'iter-sync'],
9+
api: ['classic', 'webstream', 'iter', 'iter-sync-source', 'iter-sync'],
1010
datasize: [1024 * 1024, 16 * 1024 * 1024, 64 * 1024 * 1024],
1111
n: [5],
1212
}, {
@@ -26,6 +26,8 @@ function main({ api, datasize, n }) {
2626
return benchWebStream(chunk, datasize, n, totalOps);
2727
case 'iter':
2828
return benchIter(chunk, datasize, n, totalOps);
29+
case 'iter-sync-source':
30+
return benchIterSyncSource(chunk, datasize, n, totalOps);
2931
case 'iter-sync':
3032
return benchIterSync(chunk, datasize, n, totalOps);
3133
}
@@ -101,6 +103,29 @@ function benchIter(chunk, datasize, n, totalOps) {
101103
})();
102104
}
103105

106+
function benchIterSyncSource(chunk, datasize, n, totalOps) {
107+
const { pipeTo } = require('stream/iter');
108+
109+
async function run() {
110+
let remaining = datasize;
111+
function* source() {
112+
while (remaining > 0) {
113+
const size = Math.min(remaining, chunk.length);
114+
remaining -= size;
115+
yield size === chunk.length ? chunk : chunk.subarray(0, size);
116+
}
117+
}
118+
const writer = { write() {}, writeSync() { return true; } };
119+
await pipeTo(source(), writer);
120+
}
121+
122+
(async () => {
123+
bench.start();
124+
for (let i = 0; i < n; i++) await run();
125+
bench.end(totalOps);
126+
})();
127+
}
128+
104129
function benchIterSync(chunk, datasize, n, totalOps) {
105130
const { pipeToSync } = require('stream/iter');
106131

0 commit comments

Comments
 (0)