2017-02-22 01:34:41 +08:00
|
|
|
'use strict';
|
2017-02-11 22:21:10 +08:00
|
|
|
|
|
|
|
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);
|
2017-08-20 03:55:24 +08:00
|
|
|
const noop = () => {};
|
2017-02-11 22:21:10 +08:00
|
|
|
|
2017-12-30 11:00:35 +08:00
|
|
|
function main({ n, port, address }) {
|
|
|
|
port = port === 'true' ? 0 : undefined;
|
|
|
|
address = address === 'true' ? '0.0.0.0' : undefined;
|
2017-02-11 22:21:10 +08:00
|
|
|
|
|
|
|
if (port !== undefined && address !== undefined) {
|
|
|
|
bench.start();
|
2020-01-03 21:37:27 +08:00
|
|
|
for (let i = 0; i < n; i++) {
|
2017-08-20 03:55:24 +08:00
|
|
|
dgram.createSocket('udp4').bind(port, address)
|
|
|
|
.on('error', noop)
|
|
|
|
.unref();
|
2017-02-11 22:21:10 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
} else if (port !== undefined) {
|
|
|
|
bench.start();
|
2020-01-03 21:37:27 +08:00
|
|
|
for (let i = 0; i < n; i++) {
|
2017-08-20 03:55:24 +08:00
|
|
|
dgram.createSocket('udp4')
|
|
|
|
.bind(port)
|
|
|
|
.on('error', noop)
|
|
|
|
.unref();
|
2017-02-11 22:21:10 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
} else if (port === undefined && address === undefined) {
|
|
|
|
bench.start();
|
2020-01-03 21:37:27 +08:00
|
|
|
for (let i = 0; i < n; i++) {
|
2017-08-20 03:55:24 +08:00
|
|
|
dgram.createSocket('udp4')
|
|
|
|
.bind()
|
|
|
|
.on('error', noop)
|
|
|
|
.unref();
|
2017-02-11 22:21:10 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|
|
|
|
}
|