tools,benchmark: use stricter indentation linting

Enable stricter indentation rules for benchmark code.

PR-URL: https://github.com/nodejs/node/pull/13895
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Rich Trott 2017-06-23 20:52:07 -07:00
parent 1e5e0ce862
commit 496f60489d
8 changed files with 36 additions and 32 deletions

13
benchmark/.eslintrc.yaml Normal file
View File

@ -0,0 +1,13 @@
## Benchmarks-specific linter rules
rules:
# Stylistic Issues
# http://eslint.org/docs/rules/#stylistic-issues
indent: [2, 2, {ArrayExpression: first,
CallExpression: {arguments: first},
FunctionDeclaration: {parameters: first},
FunctionExpression: {parameters: first},
MemberExpression: off,
ObjectExpression: first,
SwitchCase: 1}]
indent-legacy: 0

View File

@ -87,8 +87,8 @@ class BenchmarkProgress {
const runsPerFile = this.runsPerFile; const runsPerFile = this.runsPerFile;
const completedFiles = Math.floor(completedRuns / runsPerFile); const completedFiles = Math.floor(completedRuns / runsPerFile);
const scheduledFiles = this.benchmarks.length; const scheduledFiles = this.benchmarks.length;
const completedRunsForFile = finished ? runsPerFile : const completedRunsForFile =
completedRuns % runsPerFile; finished ? runsPerFile : completedRuns % runsPerFile;
const completedConfig = this.completedConfig; const completedConfig = this.completedConfig;
const scheduledConfig = this.scheduledConfig; const scheduledConfig = this.scheduledConfig;
@ -101,12 +101,11 @@ class BenchmarkProgress {
const percent = pad(Math.floor(completedRate * 100), 3, ' '); const percent = pad(Math.floor(completedRate * 100), 3, ' ');
const caption = finished ? 'Done\n' : this.currentFile; const caption = finished ? 'Done\n' : this.currentFile;
return `[${getTime(diff)}|% ${ return `[${getTime(diff)}|% ${percent}| ` +
percent}| ${ `${fraction(completedFiles, scheduledFiles)} files | ` +
fraction(completedFiles, scheduledFiles)} files | ${ `${fraction(completedRunsForFile, runsPerFile)} runs | ` +
fraction(completedRunsForFile, runsPerFile)} runs | ${ `${fraction(completedConfig, scheduledConfig)} configs]: ` +
fraction(completedConfig, scheduledConfig)} configs]: ${ `${caption} `;
caption} `;
} }
updateProgress(finished) { updateProgress(finished) {

View File

@ -13,9 +13,8 @@ exports.PORT = process.env.PORT || 12346;
class AutocannonBenchmarker { class AutocannonBenchmarker {
constructor() { constructor() {
this.name = 'autocannon'; this.name = 'autocannon';
this.executable = process.platform === 'win32' ? this.executable =
'autocannon.cmd' : process.platform === 'win32' ? 'autocannon.cmd' : 'autocannon';
'autocannon';
const result = child_process.spawnSync(this.executable, ['-h']); const result = child_process.spawnSync(this.executable, ['-h']);
this.present = !(result.error && result.error.code === 'ENOENT'); this.present = !(result.error && result.error.code === 'ENOENT');
} }
@ -136,19 +135,19 @@ exports.run = function(options, callback) {
benchmarker: exports.default_http_benchmarker benchmarker: exports.default_http_benchmarker
}, options); }, options);
if (!options.benchmarker) { if (!options.benchmarker) {
callback(new Error(`Could not locate required http benchmarker. See ${ callback(new Error('Could not locate required http benchmarker. See ' +
requirementsURL} for further instructions.`)); `${requirementsURL} for further instructions.`));
return; return;
} }
const benchmarker = benchmarkers[options.benchmarker]; const benchmarker = benchmarkers[options.benchmarker];
if (!benchmarker) { if (!benchmarker) {
callback(new Error(`Requested benchmarker '${ callback(new Error(`Requested benchmarker '${options.benchmarker}' ` +
options.benchmarker}' is not supported`)); 'is not supported'));
return; return;
} }
if (!benchmarker.present) { if (!benchmarker.present) {
callback(new Error(`Requested benchmarker '${ callback(new Error(`Requested benchmarker '${options.benchmarker}' ` +
options.benchmarker}' is not installed`)); 'is not installed'));
return; return;
} }

View File

@ -26,8 +26,8 @@ function compareUsingOffset(b0, b1, len, iter) {
function main(conf) { function main(conf) {
const iter = (conf.millions >>> 0) * 1e6; const iter = (conf.millions >>> 0) * 1e6;
const size = (conf.size >>> 0); const size = (conf.size >>> 0);
const method = conf.method === 'slice' ? const method =
compareUsingSlice : compareUsingOffset; conf.method === 'slice' ? compareUsingSlice : compareUsingOffset;
method(Buffer.alloc(size, 'a'), method(Buffer.alloc(size, 'a'),
Buffer.alloc(size, 'b'), Buffer.alloc(size, 'b'),
size >> 1, size >> 1,

View File

@ -20,10 +20,7 @@ const cli = CLI(`usage: ./node compare.js [options] [--] <category> ...
--filter pattern string to filter benchmark scripts --filter pattern string to filter benchmark scripts
--set variable=value set benchmark variable (can be repeated) --set variable=value set benchmark variable (can be repeated)
--no-progress don't show benchmark progress indicator --no-progress don't show benchmark progress indicator
`, { `, { arrayArgs: ['set'], boolArgs: ['no-progress'] });
arrayArgs: ['set'],
boolArgs: ['no-progress']
});
if (!cli.optional.new || !cli.optional.old) { if (!cli.optional.new || !cli.optional.old) {
cli.abort(cli.usage); cli.abort(cli.usage);
@ -85,8 +82,8 @@ if (showProgress) {
// Escape quotes (") for correct csv formatting // Escape quotes (") for correct csv formatting
conf = conf.replace(/"/g, '""'); conf = conf.replace(/"/g, '""');
console.log(`"${job.binary}", "${job.filename}", "${conf}", ${ console.log(`"${job.binary}", "${job.filename}", "${conf}", ` +
data.rate}, ${data.time}`); `${data.rate}, ${data.time}`);
if (showProgress) { if (showProgress) {
// One item in the subqueue has been completed. // One item in the subqueue has been completed.
progress.completeConfig(data); progress.completeConfig(data);

View File

@ -11,9 +11,7 @@ const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
--filter pattern string to filter benchmark scripts --filter pattern string to filter benchmark scripts
--set variable=value set benchmark variable (can be repeated) --set variable=value set benchmark variable (can be repeated)
--format [simple|csv] optional value that specifies the output format --format [simple|csv] optional value that specifies the output format
`, { `, { arrayArgs: ['set'] });
arrayArgs: ['set']
});
const benchmarks = cli.benchmarks(); const benchmarks = cli.benchmarks();
if (benchmarks.length === 0) { if (benchmarks.length === 0) {

View File

@ -13,9 +13,7 @@ const cli = CLI(`usage: ./node scatter.js [options] [--] <filename>
--runs 30 number of samples --runs 30 number of samples
--set variable=value set benchmark variable (can be repeated) --set variable=value set benchmark variable (can be repeated)
`, { `, { arrayArgs: ['set'] });
arrayArgs: ['set']
});
if (cli.items.length !== 1) { if (cli.items.length !== 1) {
cli.abort(cli.usage); cli.abort(cli.usage);