1'use strict'; 2 3const common = require('../common.js'); 4const dgram = require('dgram'); 5 6const configs = { 7 n: [1e4], 8 port: ['true', 'false'], 9 address: ['true', 'false'], 10}; 11 12const bench = common.createBenchmark(main, configs); 13const noop = () => {}; 14 15function main({ n, port, address }) { 16 port = port === 'true' ? 0 : undefined; 17 address = address === 'true' ? '0.0.0.0' : undefined; 18 19 if (port !== undefined && address !== undefined) { 20 bench.start(); 21 for (let i = 0; i < n; i++) { 22 dgram.createSocket('udp4').bind(port, address) 23 .on('error', noop) 24 .unref(); 25 } 26 bench.end(n); 27 } else if (port !== undefined) { 28 bench.start(); 29 for (let i = 0; i < n; i++) { 30 dgram.createSocket('udp4') 31 .bind(port) 32 .on('error', noop) 33 .unref(); 34 } 35 bench.end(n); 36 } else if (port === undefined && address === undefined) { 37 bench.start(); 38 for (let i = 0; i < n; i++) { 39 dgram.createSocket('udp4') 40 .bind() 41 .on('error', noop) 42 .unref(); 43 } 44 bench.end(n); 45 } 46} 47