diff options
author | Brian White <mscdex@mscdex.net> | 2018-03-16 20:35:32 -0400 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-23 13:39:16 +0100 |
commit | b41ed29b80ea1454132e5707a978ad2ebd6b29a2 (patch) | |
tree | 262b5299fc7e3e32ba08adcf8f9dba467a32875e /benchmark | |
parent | 1c8149417a5dec9b2af056f306822b8a22a09706 (diff) | |
download | node-new-b41ed29b80ea1454132e5707a978ad2ebd6b29a2.tar.gz |
stream: improve stream creation performance
PR-URL: https://github.com/nodejs/node/pull/19401
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/streams/creation.js | 55 | ||||
-rw-r--r-- | benchmark/streams/transform-creation.js | 21 |
2 files changed, 55 insertions, 21 deletions
diff --git a/benchmark/streams/creation.js b/benchmark/streams/creation.js new file mode 100644 index 0000000000..67187f91bd --- /dev/null +++ b/benchmark/streams/creation.js @@ -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'); + } +} diff --git a/benchmark/streams/transform-creation.js b/benchmark/streams/transform-creation.js deleted file mode 100644 index abfab0c8e2..0000000000 --- a/benchmark/streams/transform-creation.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; -const common = require('../common.js'); -const Transform = require('stream').Transform; -const inherits = require('util').inherits; - -const bench = common.createBenchmark(main, { - n: [1e6] -}); - -function MyTransform() { - Transform.call(this); -} -inherits(MyTransform, Transform); -MyTransform.prototype._transform = function() {}; - -function main({ n }) { - bench.start(); - for (var i = 0; i < n; ++i) - new MyTransform(); - bench.end(n); -} |