Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion benchmark/webstreams/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {

const bench = common.createBenchmark(main, {
n: [5e4],
kind: ['readable', 'pipe-to', 'pipe-through'],
kind: ['readable', 'async-iterator', 'pipe-to', 'pipe-through'],
});

const chunk = Buffer.alloc(1024);
Expand Down Expand Up @@ -37,6 +37,18 @@ async function readable(n) {
assert.strictEqual(chunks, n * 4);
}

async function asyncIterator(n) {
let chunks = 0;
bench.start();
for (let i = 0; i < n; i++) {
for await (const chunk of new ReadableStream(makeSource())) {
if (chunk) chunks++;
}
}
bench.end(n);
assert.strictEqual(chunks, n * 4);
}

async function pipeTo(n) {
let chunks = 0;
bench.start();
Expand Down Expand Up @@ -66,6 +78,9 @@ function main({ n, kind }) {
case 'readable':
readable(n);
break;
case 'async-iterator':
asyncIterator(n);
break;
case 'pipe-to':
pipeTo(n);
break;
Expand Down
Loading
Loading