diff options
author | Vse Mozhet Byt <vsemozhetbyt@gmail.com> | 2017-02-11 17:21:10 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-02-22 23:05:19 +0300 |
commit | e1573b9fb79808d8630bb37ded5dfa7e8ab29503 (patch) | |
tree | 7f6c74c8d48c091263598c17922613c3476f4981 /benchmark | |
parent | eea2eb911137e1d8c776c6aecf94026ab04ca003 (diff) |
benchmark: add dgram bind(+/- params) benchmark
Refs: https://github.com/nodejs/node/pull/11242
PR-URL: https://github.com/nodejs/node/pull/11313
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/dgram/bind-params.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/benchmark/dgram/bind-params.js b/benchmark/dgram/bind-params.js new file mode 100644 index 00000000000..6f641f7f570 --- /dev/null +++ b/benchmark/dgram/bind-params.js @@ -0,0 +1,38 @@ +'use strict'; + +const common = require('../common.js'); +const dgram = require('dgram'); + +const configs = { + n: [1e4], + port: ['true', 'false'], + address: ['true', 'false'], +}; + +const bench = common.createBenchmark(main, configs); + +function main(conf) { + const n = +conf.n; + const port = conf.port === 'true' ? 0 : undefined; + const address = conf.address === 'true' ? '0.0.0.0' : undefined; + + if (port !== undefined && address !== undefined) { + bench.start(); + for (let i = 0; i < n; i++) { + dgram.createSocket('udp4').bind(port, address).unref(); + } + bench.end(n); + } else if (port !== undefined) { + bench.start(); + for (let i = 0; i < n; i++) { + dgram.createSocket('udp4').bind(port).unref(); + } + bench.end(n); + } else if (port === undefined && address === undefined) { + bench.start(); + for (let i = 0; i < n; i++) { + dgram.createSocket('udp4').bind().unref(); + } + bench.end(n); + } +} |