0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/benchmark/dgram/bind-params.js
Ruben Bridgewater 1b6cb94761
benchmark: refactor
PR-URL: https://github.com/nodejs/node/pull/18320
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-02-01 10:49:04 +01:00

48 lines
1.0 KiB
JavaScript

'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);
const noop = () => {};
function main({ n, port, address }) {
port = port === 'true' ? 0 : undefined;
address = address === 'true' ? '0.0.0.0' : undefined;
var i;
if (port !== undefined && address !== undefined) {
bench.start();
for (i = 0; i < n; i++) {
dgram.createSocket('udp4').bind(port, address)
.on('error', noop)
.unref();
}
bench.end(n);
} else if (port !== undefined) {
bench.start();
for (i = 0; i < n; i++) {
dgram.createSocket('udp4')
.bind(port)
.on('error', noop)
.unref();
}
bench.end(n);
} else if (port === undefined && address === undefined) {
bench.start();
for (i = 0; i < n; i++) {
dgram.createSocket('udp4')
.bind()
.on('error', noop)
.unref();
}
bench.end(n);
}
}