Skip to content

Commit f5595c6

Browse files
committed
benchmark: added finished benchmark
1 parent 765dd80 commit f5595c6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

benchmark/streams/finished.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { Readable, Writable, Duplex, finished } = require('stream');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [1e5],
8+
streamType: ['readable', 'writable', 'duplex'],
9+
});
10+
11+
function main({ n, streamType }) {
12+
bench.start();
13+
14+
for (let i = 0; i < n; i++) {
15+
let stream;
16+
17+
switch (streamType) {
18+
case 'readable':
19+
stream = new Readable({ read() { this.push(null); } });
20+
break;
21+
case 'writable':
22+
stream = new Writable({ write(chunk, enc, cb) { cb(); } });
23+
stream.end();
24+
break;
25+
case 'duplex':
26+
stream = new Duplex({
27+
read() { this.push(null); },
28+
write(chunk, enc, cb) { cb(); },
29+
});
30+
stream.end();
31+
break;
32+
}
33+
34+
finished(stream, () => {});
35+
}
36+
37+
bench.end(n);
38+
}

0 commit comments

Comments
 (0)