2018-03-17 01:35:32 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
2018-07-08 06:32:23 +02:00
|
|
|
const {
|
|
|
|
Duplex,
|
|
|
|
Readable,
|
|
|
|
Transform,
|
|
|
|
Writable,
|
|
|
|
} = require('stream');
|
2018-03-17 01:35:32 +01:00
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
n: [50e6],
|
|
|
|
kind: ['duplex', 'readable', 'transform', 'writable']
|
|
|
|
});
|
|
|
|
|
|
|
|
function main({ n, kind }) {
|
|
|
|
switch (kind) {
|
|
|
|
case 'duplex':
|
|
|
|
new Duplex({});
|
|
|
|
new Duplex();
|
|
|
|
|
|
|
|
bench.start();
|
2020-01-31 16:50:00 +01:00
|
|
|
for (let i = 0; i < n; ++i)
|
2018-03-17 01:35:32 +01:00
|
|
|
new Duplex();
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
case 'readable':
|
|
|
|
new Readable({});
|
|
|
|
new Readable();
|
|
|
|
|
|
|
|
bench.start();
|
2020-01-31 16:50:00 +01:00
|
|
|
for (let i = 0; i < n; ++i)
|
2018-03-17 01:35:32 +01:00
|
|
|
new Readable();
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
case 'writable':
|
|
|
|
new Writable({});
|
|
|
|
new Writable();
|
|
|
|
|
|
|
|
bench.start();
|
2020-01-31 16:50:00 +01:00
|
|
|
for (let i = 0; i < n; ++i)
|
2018-03-17 01:35:32 +01:00
|
|
|
new Writable();
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
case 'transform':
|
|
|
|
new Transform({});
|
|
|
|
new Transform();
|
|
|
|
|
|
|
|
bench.start();
|
2020-01-31 16:50:00 +01:00
|
|
|
for (let i = 0; i < n; ++i)
|
2018-03-17 01:35:32 +01:00
|
|
|
new Transform();
|
|
|
|
bench.end(n);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('Invalid kind');
|
|
|
|
}
|
|
|
|
}
|