forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinished.js
More file actions
33 lines (26 loc) · 701 Bytes
/
Copy pathfinished.js
File metadata and controls
33 lines (26 loc) · 701 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
'use strict';
const common = require('../common');
const { Readable, Writable } = require('stream');
const { finished } = require('stream/promises');
const bench = common.createBenchmark(main, {
n: [1e7],
streamType: ['readable', 'writable'],
});
async function main({ n, streamType }) {
bench.start();
for (let i = 0; i < n; i++) {
let stream;
switch (streamType) {
case 'readable':
stream = new Readable({ read() { this.push(null); } });
stream.resume();
break;
case 'writable':
stream = new Writable({ write(chunk, enc, cb) { cb(); } });
stream.end();
break;
}
await finished(stream);
}
bench.end(n);
}