2016-01-30 13:27:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
2016-02-01 10:30:00 +00:00
|
|
|
const fork = require('child_process').fork;
|
|
|
|
const CLI = require('./_cli.js');
|
|
|
|
|
|
|
|
const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
|
|
|
|
Run each benchmark in the <category> directory a single time, more than one
|
2017-01-02 21:32:21 +00:00
|
|
|
<category> directory can be specified.
|
2016-02-01 10:30:00 +00:00
|
|
|
|
|
|
|
--filter pattern string to filter benchmark scripts
|
|
|
|
--set variable=value set benchmark variable (can be repeated)
|
2016-08-03 11:40:53 +00:00
|
|
|
--format [simple|csv] optional value that specifies the output format
|
2017-06-24 03:52:07 +00:00
|
|
|
`, { arrayArgs: ['set'] });
|
2016-02-01 10:30:00 +00:00
|
|
|
const benchmarks = cli.benchmarks();
|
|
|
|
|
|
|
|
if (benchmarks.length === 0) {
|
2016-08-03 11:40:53 +00:00
|
|
|
console.error('No benchmarks found');
|
|
|
|
process.exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const validFormats = ['csv', 'simple'];
|
|
|
|
const format = cli.optional.format || 'simple';
|
|
|
|
if (!validFormats.includes(format)) {
|
|
|
|
console.error('Invalid format detected');
|
|
|
|
process.exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format === 'csv') {
|
|
|
|
console.log('"filename", "configuration", "rate", "time"');
|
2016-01-30 13:27:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 10:30:00 +00:00
|
|
|
(function recursive(i) {
|
|
|
|
const filename = benchmarks[i];
|
|
|
|
const child = fork(path.resolve(__dirname, filename), cli.optional.set);
|
2016-01-30 13:27:02 +00:00
|
|
|
|
2016-08-03 11:40:53 +00:00
|
|
|
if (format !== 'csv') {
|
|
|
|
console.log();
|
|
|
|
console.log(filename);
|
|
|
|
}
|
2016-01-30 13:27:02 +00:00
|
|
|
|
2019-02-05 06:06:08 +00:00
|
|
|
child.on('message', (data) => {
|
2017-01-15 18:59:13 +00:00
|
|
|
if (data.type !== 'report') {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-01 10:30:00 +00:00
|
|
|
// Construct configuration string, " A=a, B=b, ..."
|
|
|
|
let conf = '';
|
|
|
|
for (const key of Object.keys(data.conf)) {
|
2017-04-17 01:01:12 +00:00
|
|
|
conf += ` ${key}=${JSON.stringify(data.conf[key])}`;
|
2016-02-01 10:30:00 +00:00
|
|
|
}
|
2019-03-07 00:03:53 +00:00
|
|
|
// Delete first space of the configuration
|
2016-08-03 11:40:53 +00:00
|
|
|
conf = conf.slice(1);
|
|
|
|
if (format === 'csv') {
|
|
|
|
// Escape quotes (") for correct csv formatting
|
|
|
|
conf = conf.replace(/"/g, '""');
|
|
|
|
console.log(`"${data.name}", "${conf}", ${data.rate}, ${data.time}`);
|
|
|
|
} else {
|
2017-01-01 02:50:25 +00:00
|
|
|
var rate = data.rate.toString().split('.');
|
2017-06-16 15:04:33 +00:00
|
|
|
rate[0] = rate[0].replace(/(\d)(?=(?:\d\d\d)+(?!\d))/g, '$1,');
|
2017-01-01 02:50:25 +00:00
|
|
|
rate = (rate[1] ? rate.join('.') : rate[0]);
|
2016-12-20 19:57:28 +00:00
|
|
|
console.log(`${data.name} ${conf}: ${rate}`);
|
2016-08-03 11:40:53 +00:00
|
|
|
}
|
2016-02-01 10:30:00 +00:00
|
|
|
});
|
2016-01-30 13:27:02 +00:00
|
|
|
|
2019-02-05 06:06:08 +00:00
|
|
|
child.once('close', (code) => {
|
2016-01-30 13:27:02 +00:00
|
|
|
if (code) {
|
|
|
|
process.exit(code);
|
2016-02-01 10:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are more benchmarks execute the next
|
|
|
|
if (i + 1 < benchmarks.length) {
|
|
|
|
recursive(i + 1);
|
2016-01-30 13:27:02 +00:00
|
|
|
}
|
|
|
|
});
|
2016-02-01 10:30:00 +00:00
|
|
|
})(0);
|