We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dbe6c5f commit 8a89642Copy full SHA for 8a89642
1 file changed
benchmark/streams/readable-from.js
@@ -5,15 +5,58 @@ const Readable = require('stream').Readable;
5
6
const bench = common.createBenchmark(main, {
7
n: [1e7],
8
+ type: ['array', 'sync-generator-with-sync-values', 'sync-generator-with-async-values', 'async-generator'],
9
});
10
-async function main({ n }) {
11
- const arr = [];
12
- for (let i = 0; i < n; i++) {
13
- arr.push(`${i}`);
+async function main({ n, type }) {
+ let fromArg;
+
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-with-sync-values': {
25
+ fromArg = (function* () {
26
27
+ yield `${i}`;
28
29
+ })();
30
31
32
33
34
+ case 'sync-generator-with-async-values': {
35
36
37
+ yield Promise.resolve(`${i}`);
38
39
40
41
42
43
44
+ case 'async-generator': {
45
+ fromArg = (async function* () {
46
47
48
49
50
51
52
53
54
+ default: {
55
+ throw new Error(`Unknown type: ${type}`);
56
57
}
58
- const s = new Readable.from(arr);
59
+ const s = new Readable.from(fromArg);
60
61
bench.start();
62
s.on('data', (data) => {
0 commit comments