forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.js
More file actions
42 lines (34 loc) · 984 Bytes
/
compose.js
File metadata and controls
42 lines (34 loc) · 984 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const common = require('../common.js');
const {
PassThrough,
Readable,
Writable,
compose,
} = require('node:stream');
const bench = common.createBenchmark(main, {
n: [1e3],
});
function main({ n }) {
const cachedPassThroughs = [];
const cachedReadables = [];
const cachedWritables = [];
for (let i = 0; i < n; i++) {
const numberOfPassThroughs = 100;
const passThroughs = [];
for (let i = 0; i < numberOfPassThroughs; i++) {
passThroughs.push(new PassThrough());
}
const readable = Readable.from(['hello', 'world']);
const writable = new Writable({ objectMode: true, write: (chunk, encoding, cb) => cb() });
cachedPassThroughs.push(passThroughs);
cachedReadables.push(readable);
cachedWritables.push(writable);
}
bench.start();
for (let i = 0; i < n; i++) {
const composed = compose(cachedReadables[i], ...cachedPassThroughs[i], cachedWritables[i]);
composed.end();
}
bench.end(n);
}