diff options
Diffstat (limited to 'benchmark/compare.js')
-rw-r--r-- | benchmark/compare.js | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/benchmark/compare.js b/benchmark/compare.js index ea431b18cb4..af36d1c4239 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -3,6 +3,7 @@ const fork = require('child_process').fork; const path = require('path'); const CLI = require('./_cli.js'); +const BenchmarkProgress = require('./_benchmark_progress.js'); // // Parse arguments @@ -13,13 +14,15 @@ const cli = CLI(`usage: ./node compare.js [options] [--] <category> ... The output is formatted as csv, which can be processed using for example 'compare.R'. - --new ./new-node-binary new node binary (required) - --old ./old-node-binary old node binary (required) - --runs 30 number of samples - --filter pattern string to filter benchmark scripts - --set variable=value set benchmark variable (can be repeated) + --new ./new-node-binary new node binary (required) + --old ./old-node-binary old node binary (required) + --runs 30 number of samples + --filter pattern string to filter benchmark scripts + --set variable=value set benchmark variable (can be repeated) + --no-progress don't show benchmark progress indicator `, { - arrayArgs: ['set'] + arrayArgs: ['set'], + boolArgs: ['no-progress'] }); if (!cli.optional.new || !cli.optional.old) { @@ -39,6 +42,9 @@ if (benchmarks.length === 0) { // Create queue from the benchmarks list such both node versions are tested // `runs` amount of times each. +// Note: BenchmarkProgress relies on this order to estimate +// how much runs remaining for a file. All benchmarks generated from +// the same file must be run consecutively. const queue = []; for (const filename of benchmarks) { for (let iter = 0; iter < runs; iter++) { @@ -47,10 +53,20 @@ for (const filename of benchmarks) { } } } +// queue.length = binary.length * runs * benchmarks.length // Print csv header console.log('"binary", "filename", "configuration", "rate", "time"'); +const kStartOfQueue = 0; + +const showProgress = !cli.optional['no-progress']; +let progress; +if (showProgress) { + progress = new BenchmarkProgress(queue, benchmarks); + progress.startQueue(kStartOfQueue); +} + (function recursive(i) { const job = queue[i]; @@ -59,18 +75,26 @@ console.log('"binary", "filename", "configuration", "rate", "time"'); }); child.on('message', function(data) { - // Construct configuration string, " A=a, B=b, ..." - let conf = ''; - for (const key of Object.keys(data.conf)) { - conf += ' ' + key + '=' + JSON.stringify(data.conf[key]); - } - conf = conf.slice(1); + if (data.type === 'report') { + // Construct configuration string, " A=a, B=b, ..." + let conf = ''; + for (const key of Object.keys(data.conf)) { + conf += ' ' + key + '=' + JSON.stringify(data.conf[key]); + } + conf = conf.slice(1); + // Escape quotes (") for correct csv formatting + conf = conf.replace(/"/g, '""'); - // Escape quotes (") for correct csv formatting - conf = conf.replace(/"/g, '""'); - - console.log(`"${job.binary}", "${job.filename}", "${conf}", ` + - `${data.rate}, ${data.time}`); + console.log(`"${job.binary}", "${job.filename}", "${conf}", ` + + `${data.rate}, ${data.time}`); + if (showProgress) { + // One item in the subqueue has been completed. + progress.completeConfig(data); + } + } else if (showProgress && data.type === 'config') { + // The child has computed the configurations, ready to run subqueue. + progress.startSubqueue(data, i); + } }); child.once('close', function(code) { @@ -78,10 +102,13 @@ console.log('"binary", "filename", "configuration", "rate", "time"'); process.exit(code); return; } + if (showProgress) { + progress.completeRun(job); + } // If there are more benchmarks execute the next if (i + 1 < queue.length) { recursive(i + 1); } }); -})(0); +})(kStartOfQueue); |