diff options
author | Brian White <mscdex@mscdex.net> | 2017-05-27 20:35:13 -0400 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2017-06-01 22:00:50 -0400 |
commit | 656bb71867ffb7a0ce9edf5b60cb9303ec915576 (patch) | |
tree | ef7c9dc873f17fee386e68e168674ef6e48e2444 /benchmark | |
parent | 8d7ff6dd7561c7c8012466542ecabec2a5bc106d (diff) | |
download | android-node-v8-656bb71867ffb7a0ce9edf5b60cb9303ec915576.tar.gz android-node-v8-656bb71867ffb7a0ce9edf5b60cb9303ec915576.tar.bz2 android-node-v8-656bb71867ffb7a0ce9edf5b60cb9303ec915576.zip |
dns: improve callback performance
It appears that either c-ares no longer calls callbacks synchronously
or we have since explicitly taken care of the scenarios in which
c-ares would call callbacks synchronously (e.g. resolving an IP
address or an empty hostname). Therefore we no longer need to have
machinery in place to handle possible synchronous callback invocation.
This improves performance significantly.
PR-URL: https://github.com/nodejs/node/pull/13261
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/dns/lookup.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/benchmark/dns/lookup.js b/benchmark/dns/lookup.js new file mode 100644 index 0000000000..ebe9d05695 --- /dev/null +++ b/benchmark/dns/lookup.js @@ -0,0 +1,38 @@ +'use strict'; + +const common = require('../common.js'); +const lookup = require('dns').lookup; + +const bench = common.createBenchmark(main, { + name: ['', '127.0.0.1', '::1'], + all: [true, false], + n: [5e6] +}); + +function main(conf) { + const name = conf.name; + const n = +conf.n; + const all = !!conf.all; + var i = 0; + + if (all) { + const opts = { all: true }; + bench.start(); + (function cb(err, results) { + if (i++ === n) { + bench.end(n); + return; + } + lookup(name, opts, cb); + })(); + } else { + bench.start(); + (function cb(err, result) { + if (i++ === n) { + bench.end(n); + return; + } + lookup(name, cb); + })(); + } +} |