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-c2s-cork.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-c2s-cork.js')
-rw-r--r-- | benchmark/net/net-c2s-cork.js | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js index a6582caa16..55bb99f6f7 100644 --- a/benchmark/net/net-c2s-cork.js +++ b/benchmark/net/net-c2s-cork.js @@ -2,6 +2,7 @@ 'use strict'; const common = require('../common.js'); +const net = require('net'); const PORT = common.PORT; const bench = common.createBenchmark(main, { @@ -10,17 +11,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,34 +31,6 @@ function main(conf) { throw new Error(`invalid type: ${type}`); } - server(); -} - -const net = require('net'); - -function Writer() { - this.received = 0; - this.writable = true; -} - -Writer.prototype.write = function(chunk, encoding, cb) { - this.received += chunk.length; - - if (typeof encoding === 'function') - encoding(); - else if (typeof cb === 'function') - cb(); - - return true; -}; - -// doesn't matter, never emits anything. -Writer.prototype.on = function() {}; -Writer.prototype.once = function() {}; -Writer.prototype.emit = function() {}; -Writer.prototype.prependListener = function() {}; - -function server() { const writer = new Writer(); // the actual benchmark. @@ -95,3 +61,25 @@ function server() { }); }); } + +function Writer() { + this.received = 0; + this.writable = true; +} + +Writer.prototype.write = function(chunk, encoding, cb) { + this.received += chunk.length; + + if (typeof encoding === 'function') + encoding(); + else if (typeof cb === 'function') + cb(); + + return true; +}; + +// doesn't matter, never emits anything. +Writer.prototype.on = function() {}; +Writer.prototype.once = function() {}; +Writer.prototype.emit = function() {}; +Writer.prototype.prependListener = function() {}; |