Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: fix issues in dns benchmark #14936

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions benchmark/dns/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ const lookup = require('dns').lookup;

const bench = common.createBenchmark(main, {
name: ['', '127.0.0.1', '::1'],
all: [true, false],
all: ['true', 'false'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually breaks the intention of the Boolean. The value will be coerced to a Boolean again in line 15 and !!'false' === true. So you might just change this to [1, 0] instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR Oh, good catch.

Copy link
Member

@Trott Trott Aug 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possibility is to leave them as strings but change the assignment to something like: const all = conf.all === 'true' ? true : false;

To me, this has the advantage of being more readable and also seems to be at least a little bit in line with what some other benchmarks do. Of course, @BridgeAR's suggestion works too if that seems preferable.

n: [5e6]
});

function main(conf) {
const name = conf.name;
const n = +conf.n;
const all = !!conf.all;
const all = conf.all === 'true' ? true : false;
var i = 0;

if (all) {
const opts = { all: true };
bench.start();
(function cb(err, results) {
(function cb() {
if (i++ === n) {
bench.end(n);
return;
Expand All @@ -27,7 +27,7 @@ function main(conf) {
})();
} else {
bench.start();
(function cb(err, result) {
(function cb() {
if (i++ === n) {
bench.end(n);
return;
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-benchmark-dns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

require('../common');

// Minimal test for dns benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');

const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(runjs,
['--set', 'n=1',
'--set', 'all=false',
'--set', 'name=127.0.0.1',
'dns'],
{ env });

child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});