diff options
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); - }); - }); -} |