-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add dgram bind(+/- params) benchmark
- Loading branch information
1 parent
c969047
commit 1162e28
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |