Skip to content

Commit

Permalink
benchmark: add stream destroy benchmark
Browse files Browse the repository at this point in the history
PR-URL: #44533
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Erick Wendel <[email protected]>
  • Loading branch information
xtx1130 authored and RafaelGSS committed Sep 26, 2022
1 parent 457673b commit 54870ea
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions benchmark/streams/destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';
const common = require('../common.js');
const {
Duplex,
Readable,
Transform,
Writable,
} = require('stream');

const bench = common.createBenchmark(main, {
n: [1e6],
kind: ['duplex', 'readable', 'transform', 'writable']
});

function main({ n, kind }) {
switch (kind) {
case 'duplex':
new Duplex({});
new Duplex();

bench.start();
for (let i = 0; i < n; ++i)
new Duplex().destroy();
bench.end(n);
break;
case 'readable':
new Readable({});
new Readable();

bench.start();
for (let i = 0; i < n; ++i)
new Readable().destroy();
bench.end(n);
break;
case 'writable':
new Writable({});
new Writable();

bench.start();
for (let i = 0; i < n; ++i)
new Writable().destroy();
bench.end(n);
break;
case 'transform':
new Transform({});
new Transform();

bench.start();
for (let i = 0; i < n; ++i)
new Transform().destroy();
bench.end(n);
break;
default:
throw new Error('Invalid kind');
}
}

0 comments on commit 54870ea

Please sign in to comment.