Skip to content

Commit 2782884

Browse files
committed
benchmark: add bytes variant to webstreams async-iterator
1 parent 1594ac2 commit 2782884

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

benchmark/webstreams/readable-async-iterator.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,40 @@ const {
66

77
const bench = common.createBenchmark(main, {
88
n: [1e5],
9+
type: ['normal', 'bytes'],
910
});
1011

1112

12-
async function main({ n }) {
13-
const rs = new ReadableStream({
14-
pull: function(controller) {
15-
controller.enqueue(1);
16-
},
17-
});
13+
async function main({ n, type }) {
14+
const rs = type === 'bytes' ?
15+
new ReadableStream({
16+
type: 'bytes',
17+
pull: function(controller) {
18+
controller.enqueue(new Uint8Array(1));
19+
},
20+
}) :
21+
new ReadableStream({
22+
pull: function(controller) {
23+
controller.enqueue(1);
24+
},
25+
});
1826

1927
let x = 0;
2028

2129
bench.start();
22-
for await (const chunk of rs) {
23-
x += chunk;
24-
if (x > n) {
25-
break;
30+
if (type === 'bytes') {
31+
for await (const chunk of rs) {
32+
x += chunk.byteLength;
33+
if (x > n) {
34+
break;
35+
}
36+
}
37+
} else {
38+
for await (const chunk of rs) {
39+
x += chunk;
40+
if (x > n) {
41+
break;
42+
}
2643
}
2744
}
2845
// Use x to ensure V8 does not optimize away the loop as a noop.

0 commit comments

Comments
 (0)