Skip to content

Commit 3b5bace

Browse files
mcollinaRafaelGSS
authored andcommitted
benchmark: add bytes variant to webstreams async-iterator
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #64291 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f249614 commit 3b5bace

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
constbench=common.createBenchmark(main,{
88
n: [1e5],
9+
type: ['normal','bytes'],
910
});
1011

1112

12-
asyncfunctionmain({ n }){
13-
constrs=newReadableStream({
14-
pull: function(controller){
15-
controller.enqueue(1);
16-
},
17-
});
13+
asyncfunctionmain({ n, type }){
14+
constrs=type==='bytes' ?
15+
newReadableStream({
16+
type: 'bytes',
17+
pull: function(controller){
18+
controller.enqueue(newUint8Array(1));
19+
},
20+
}) :
21+
newReadableStream({
22+
pull: function(controller){
23+
controller.enqueue(1);
24+
},
25+
});
1826

1927
letx=0;
2028

2129
bench.start();
22-
forawait(constchunkofrs){
23-
x+=chunk;
24-
if(x>n){
25-
break;
30+
if(type==='bytes'){
31+
forawait(constchunkofrs){
32+
x+=chunk.byteLength;
33+
if(x>n){
34+
break;
35+
}
36+
}
37+
}else{
38+
forawait(constchunkofrs){
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)