blob: 0d7e4737e3a15ac70dd104f0015ec71a1e446f32 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
'use strict';
const common = require('../common.js');
const {
ReadableStream,
} = require('node:stream/web');
const bench = common.createBenchmark(main, {
n: [1e5],
});
async function main({ n }) {
const rs = new ReadableStream({
pull: function(controller) {
controller.enqueue(1);
}
});
let x = 0;
bench.start();
for await (const chunk of rs) {
x += chunk;
if (x > n) {
break;
}
}
// Use x to ensure V8 does not optimize away the loop as a noop.
console.assert(x);
bench.end(n);
}
|