Skip to content

Commit e1573b9

Browse files
vsemozhetbytaddaleax
authored andcommittedFeb 22, 2017
benchmark: add dgram bind(+/- params) benchmark
Refs: #11242 PR-URL: #11313 Reviewed-By: Brian White <[email protected]>
1 parent eea2eb9 commit e1573b9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
 

‎benchmark/dgram/bind-params.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const dgram = require('dgram');
5+
6+
const configs = {
7+
n: [1e4],
8+
port: ['true', 'false'],
9+
address: ['true', 'false'],
10+
};
11+
12+
const bench = common.createBenchmark(main, configs);
13+
14+
function main(conf) {
15+
const n = +conf.n;
16+
const port = conf.port === 'true' ? 0 : undefined;
17+
const address = conf.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).unref();
23+
}
24+
bench.end(n);
25+
} else if (port !== undefined) {
26+
bench.start();
27+
for (let i = 0; i < n; i++) {
28+
dgram.createSocket('udp4').bind(port).unref();
29+
}
30+
bench.end(n);
31+
} else if (port === undefined && address === undefined) {
32+
bench.start();
33+
for (let i = 0; i < n; i++) {
34+
dgram.createSocket('udp4').bind().unref();
35+
}
36+
bench.end(n);
37+
}
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.