diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-12-30 03:56:44 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-01-23 01:29:23 +0100 |
commit | 19bdfa53804918a0da5b5e4771dfc7761dc21274 (patch) | |
tree | e69d379765724d95672a950b3ca301f353885c97 /benchmark/net/net-s2c.js | |
parent | d163a6b8c2ff98a00581a7c62fad9d2232cbb1a9 (diff) | |
download | android-node-v8-19bdfa53804918a0da5b5e4771dfc7761dc21274.tar.gz android-node-v8-19bdfa53804918a0da5b5e4771dfc7761dc21274.tar.bz2 android-node-v8-19bdfa53804918a0da5b5e4771dfc7761dc21274.zip |
benchmark: (net) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/net/net-s2c.js')
-rw-r--r-- | benchmark/net/net-s2c.js | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js index 9fec2d8577..2ddf8fd6c5 100644 --- a/benchmark/net/net-s2c.js +++ b/benchmark/net/net-s2c.js @@ -10,17 +10,10 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var dur; -var len; -var type; var chunk; var encoding; -function main(conf) { - dur = +conf.dur; - len = +conf.len; - type = conf.type; - +function main({ dur, len, type }) { switch (type) { case 'buf': chunk = Buffer.alloc(len, 'x'); @@ -37,7 +30,29 @@ function main(conf) { throw new Error(`invalid type: ${type}`); } - server(); + const reader = new Reader(); + const writer = new Writer(); + + // the actual benchmark. + const server = net.createServer(function(socket) { + reader.pipe(socket); + }); + + server.listen(PORT, function() { + const socket = net.connect(PORT); + socket.on('connect', function() { + bench.start(); + + socket.pipe(writer); + + setTimeout(function() { + const bytes = writer.received; + const gbits = (bytes * 8) / (1024 * 1024 * 1024); + bench.end(gbits); + process.exit(0); + }, dur * 1000); + }); + }); } const net = require('net'); @@ -84,30 +99,3 @@ Reader.prototype.pipe = function(dest) { this.flow(); return dest; }; - - -function server() { - const reader = new Reader(); - const writer = new Writer(); - - // the actual benchmark. - const server = net.createServer(function(socket) { - reader.pipe(socket); - }); - - server.listen(PORT, function() { - const socket = net.connect(PORT); - socket.on('connect', function() { - bench.start(); - - socket.pipe(writer); - - setTimeout(function() { - const bytes = writer.received; - const gbits = (bytes * 8) / (1024 * 1024 * 1024); - bench.end(gbits); - process.exit(0); - }, dur * 1000); - }); - }); -} |