From cd9bc8bc50d9013548f1180cf9accf96049fdd6e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 30 Dec 2017 04:00:35 +0100 Subject: [PATCH] benchmark: (dgram) use destructuring PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- benchmark/dgram/array-vs-concat.js | 26 ++++---------------------- benchmark/dgram/bind-params.js | 7 +++---- benchmark/dgram/multi-buffer.js | 25 +++---------------------- benchmark/dgram/offset-length.js | 21 +++------------------ benchmark/dgram/single-buffer.js | 21 +++------------------ 5 files changed, 16 insertions(+), 84 deletions(-) diff --git a/benchmark/dgram/array-vs-concat.js b/benchmark/dgram/array-vs-concat.js index 7ee4e2d3acb6e1..a7843a9c7f7c28 100644 --- a/benchmark/dgram/array-vs-concat.js +++ b/benchmark/dgram/array-vs-concat.js @@ -2,6 +2,7 @@ 'use strict'; const common = require('../common.js'); +const dgram = require('dgram'); const PORT = common.PORT; // `num` is the number of send requests to queue up each time. @@ -15,34 +16,15 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var dur; -var len; -var num; -var type; -var chunk; -var chunks; - -function main(conf) { - dur = +conf.dur; - len = +conf.len; - num = +conf.num; - type = conf.type; - chunks = +conf.chunks; - - chunk = []; +function main({ dur, len, num, type, chunks }) { + const chunk = []; for (var i = 0; i < chunks; i++) { chunk.push(Buffer.allocUnsafe(Math.round(len / chunks))); } - server(); -} - -const dgram = require('dgram'); - -function server() { + // Server var sent = 0; const socket = dgram.createSocket('udp4'); - const onsend = type === 'concat' ? onsendConcat : onsendMulti; function onsendConcat() { diff --git a/benchmark/dgram/bind-params.js b/benchmark/dgram/bind-params.js index 411bef98adcf7c..5f7999f7a39241 100644 --- a/benchmark/dgram/bind-params.js +++ b/benchmark/dgram/bind-params.js @@ -12,10 +12,9 @@ const configs = { const bench = common.createBenchmark(main, configs); const noop = () => {}; -function main(conf) { - const n = +conf.n; - const port = conf.port === 'true' ? 0 : undefined; - const address = conf.address === 'true' ? '0.0.0.0' : undefined; +function main({ n, port, address }) { + port = port === 'true' ? 0 : undefined; + address = address === 'true' ? '0.0.0.0' : undefined; if (port !== undefined && address !== undefined) { bench.start(); diff --git a/benchmark/dgram/multi-buffer.js b/benchmark/dgram/multi-buffer.js index 15f70760abfd9e..ee74c584e45278 100644 --- a/benchmark/dgram/multi-buffer.js +++ b/benchmark/dgram/multi-buffer.js @@ -2,6 +2,7 @@ 'use strict'; const common = require('../common.js'); +const dgram = require('dgram'); const PORT = common.PORT; // `num` is the number of send requests to queue up each time. @@ -15,31 +16,11 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var dur; -var len; -var num; -var type; -var chunk; -var chunks; - -function main(conf) { - dur = +conf.dur; - len = +conf.len; - num = +conf.num; - type = conf.type; - chunks = +conf.chunks; - - chunk = []; +function main({ dur, len, num, type, chunks }) { + const chunk = []; for (var i = 0; i < chunks; i++) { chunk.push(Buffer.allocUnsafe(Math.round(len / chunks))); } - - server(); -} - -const dgram = require('dgram'); - -function server() { var sent = 0; var received = 0; const socket = dgram.createSocket('udp4'); diff --git a/benchmark/dgram/offset-length.js b/benchmark/dgram/offset-length.js index 7f5a02afe58107..8a2df9ac67c1b6 100644 --- a/benchmark/dgram/offset-length.js +++ b/benchmark/dgram/offset-length.js @@ -2,6 +2,7 @@ 'use strict'; const common = require('../common.js'); +const dgram = require('dgram'); const PORT = common.PORT; // `num` is the number of send requests to queue up each time. @@ -14,24 +15,8 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var dur; -var len; -var num; -var type; -var chunk; - -function main(conf) { - dur = +conf.dur; - len = +conf.len; - num = +conf.num; - type = conf.type; - chunk = Buffer.allocUnsafe(len); - server(); -} - -const dgram = require('dgram'); - -function server() { +function main({ dur, len, num, type }) { + const chunk = Buffer.allocUnsafe(len); var sent = 0; var received = 0; const socket = dgram.createSocket('udp4'); diff --git a/benchmark/dgram/single-buffer.js b/benchmark/dgram/single-buffer.js index 454662b5425df7..0bf650d265c177 100644 --- a/benchmark/dgram/single-buffer.js +++ b/benchmark/dgram/single-buffer.js @@ -2,6 +2,7 @@ 'use strict'; const common = require('../common.js'); +const dgram = require('dgram'); const PORT = common.PORT; // `num` is the number of send requests to queue up each time. @@ -14,24 +15,8 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var dur; -var len; -var num; -var type; -var chunk; - -function main(conf) { - dur = +conf.dur; - len = +conf.len; - num = +conf.num; - type = conf.type; - chunk = Buffer.allocUnsafe(len); - server(); -} - -const dgram = require('dgram'); - -function server() { +function main({ dur, len, num, type }) { + const chunk = Buffer.allocUnsafe(len); var sent = 0; var received = 0; const socket = dgram.createSocket('udp4');