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

benchmark: add --format csv option #7961

Closed
wants to merge 3 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
10 changes: 5 additions & 5 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Benchmark(fn, options) {
Benchmark.prototype._parseArgs = function(argv, options) {
const cliOptions = Object.assign({}, options);

// Parse configuarion arguments
// Parse configuration arguments
for (const arg of argv) {
const match = arg.match(/^(.+?)=([\s\S]*)$/);
if (!match || !match[1]) {
Expand All @@ -52,7 +52,7 @@ Benchmark.prototype._queue = function(options) {
const queue = [];
const keys = Object.keys(options);

// Perform a depth-first walk though all options to genereate a
// Perform a depth-first walk though all options to generate a
// configuration list that contains all combinations.
function recursive(keyIndex, prevConfig) {
const key = keys[keyIndex];
Expand Down Expand Up @@ -171,9 +171,9 @@ Benchmark.prototype._run = function() {
};

Benchmark.prototype.start = function() {
if (this._started)
if (this._started) {
throw new Error('Called start more than once in a single benchmark');

}
this._started = true;
this._time = process.hrtime();
};
Expand All @@ -195,7 +195,7 @@ Benchmark.prototype.end = function(operations) {
};

function formatResult(data) {
// Construct confiuration string, " A=a, B=b, ..."
// Construct configuration string, " A=a, B=b, ..."
let conf = '';
for (const key of Object.keys(data.conf)) {
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
Expand Down
5 changes: 3 additions & 2 deletions benchmark/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const benchmarks = cli.benchmarks();

if (benchmarks.length === 0) {
console.error('no benchmarks found');
process.exit(1);
process.exitCode = 1;
return;
}

// Create queue from the benchmarks list such both node versions are tested
Expand Down Expand Up @@ -65,7 +66,7 @@ console.log('"binary", "filename", "configuration", "rate", "time"');
}
conf = conf.slice(1);

// Escape qoutes (") for correct csv formatting
// Escape quotes (") for correct csv formatting
conf = conf.replace(/"/g, '""');

console.log(`"${job.binary}", "${job.filename}", "${conf}", ` +
Expand Down
35 changes: 29 additions & 6 deletions benchmark/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,54 @@ const cli = CLI(`usage: ./node run.js [options] [--] <category> ...
--filter pattern string to filter benchmark scripts
--set variable=value set benchmark variable (can be repeated)
--format [simple|csv] optional value that specifies the output format
`, {
arrayArgs: ['set']
});
const benchmarks = cli.benchmarks();

if (benchmarks.length === 0) {
console.error('no benchmarks found');
process.exit(1);
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"');
}

(function recursive(i) {
const filename = benchmarks[i];
const child = fork(path.resolve(__dirname, filename), cli.optional.set);

console.log();
console.log(filename);
if (format !== 'csv') {
console.log();
console.log(filename);
}

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]);
}

console.log(`${data.name}${conf}: ${data.rate}`);
// delete first space of the configuration
conf = conf.slice(1);
Copy link
Contributor Author

@adrian-nitu-92 adrian-nitu-92 Aug 9, 2016

Choose a reason for hiding this comment

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

This line can be removed if I reformat 57&59. I like this version better because I don't think you should rely on spaces in strings you are concatenating.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, just keep it.

if (format === 'csv') {
// Escape quotes (") for correct csv formatting
conf = conf.replace(/"/g, '""');
console.log(`"${data.name}", "${conf}", ${data.rate}, ${data.time}`);
} else {
console.log(`${data.name} ${conf}: ${data.rate}`);
}
});

child.once('close', function(code) {
Expand Down