Skip to content

Commit 63aa6aa

Browse files
committed
benchmark: add more cases to Readable.from
1 parent 91a21a2 commit 63aa6aa

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

benchmark/streams/readable-from.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,48 @@ const Readable = require('stream').Readable;
55

66
const bench = common.createBenchmark(main, {
77
n: [1e7],
8+
type: ['array', 'sync-generator', 'async-generator'],
89
});
910

10-
async function main({ n }) {
11-
const arr = [];
12-
for (let i = 0; i < n; i++) {
13-
arr.push(`${i}`);
11+
async function main({ n, type }) {
12+
let fromArg;
13+
14+
switch (type) {
15+
case 'array': {
16+
fromArg = [];
17+
for (let i = 0; i < n; i++) {
18+
fromArg.push(`${i}`);
19+
}
20+
21+
break;
22+
}
23+
24+
case 'sync-generator': {
25+
fromArg = (function* () {
26+
for (let i = 0; i < n; i++) {
27+
yield `${i}`;
28+
}
29+
})();
30+
31+
break;
32+
}
33+
34+
case 'async-generator': {
35+
fromArg = (async function* () {
36+
for (let i = 0; i < n; i++) {
37+
yield `${i}`;
38+
}
39+
})();
40+
41+
break;
42+
}
43+
44+
default: {
45+
throw new Error(`Unknown type: ${type}`);
46+
}
1447
}
1548

16-
const s = new Readable.from(arr);
49+
const s = new Readable.from(fromArg);
1750

1851
bench.start();
1952
s.on('data', (data) => {

0 commit comments

Comments
 (0)