-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: improve stream creation performance
- Loading branch information
Showing
4 changed files
with
73 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const Duplex = require('stream').Duplex; | ||
const Readable = require('stream').Readable; | ||
const Transform = require('stream').Transform; | ||
const Writable = require('stream').Writable; | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [50e6], | ||
kind: ['duplex', 'readable', 'transform', 'writable'] | ||
}); | ||
|
||
function main({ n, kind }) { | ||
var i = 0; | ||
switch (kind) { | ||
case 'duplex': | ||
new Duplex({}); | ||
new Duplex(); | ||
|
||
bench.start(); | ||
for (; i < n; ++i) | ||
new Duplex(); | ||
bench.end(n); | ||
break; | ||
case 'readable': | ||
new Readable({}); | ||
new Readable(); | ||
|
||
bench.start(); | ||
for (; i < n; ++i) | ||
new Readable(); | ||
bench.end(n); | ||
break; | ||
case 'writable': | ||
new Writable({}); | ||
new Writable(); | ||
|
||
bench.start(); | ||
for (; i < n; ++i) | ||
new Writable(); | ||
bench.end(n); | ||
break; | ||
case 'transform': | ||
new Transform({}); | ||
new Transform(); | ||
|
||
bench.start(); | ||
for (; i < n; ++i) | ||
new Transform(); | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Invalid kind'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters