@ -73,6 +73,20 @@ function writeTableFooter() {
/* Helpers */
function printHelp() {
util.puts("Usage: run [options]");
util.puts("");
util.puts("Runs PEG.js benchmark suite.");
util.puts("");
util.puts("Options:");
util.puts(" -n, --run-count <n> number of runs (default: 10)");
util.puts(" --track-line-and-column make tested parsers track line and column");
}
function exitSuccess() {
process.exit(0);
}
function exitFailure() {
process.exit(1);
}
@ -82,28 +96,58 @@ function abort(message) {
exitFailure();
}
/* Main */
/* Arguments */
var args = process.argv.slice(2); // Trim "node" and the script path.
switch (args.length) {
case 0:
var runCount = 10;
break;
case 1:
var runCount = parseInt(args[0]);
if (isNaN(runCount) || runCount <= 0) {
abort("Number of runs must be a positive integer.");
}
break;
default:
abort("Too many arguments.");
function isOption(arg) {
return /^-/.test(arg);
}
function nextArg() {
args.shift();
}
util.puts("Each test is run " + runCount + " times.");
util.puts("");
/* Main */
var runCount = 10;
var options = { trackLineAndColumn: false };
while (args.length > 0 && isOption(args[0])) {
switch (args[0]) {
case "-n":
case "--run-count":
nextArg();
if (args.length === 0) {
abort("Missing parameter of the -n/--run-count option.");
}
var runCount = parseInt(args[0]);
if (isNaN(runCount) || runCount <= 0) {
abort("Number of runs must be a positive integer.");
}
break;
case "--track-line-and-column":
options.trackLineAndColumn = true;
break;
case "-h":
case "--help":
printHelp();
exitSuccess();
break;
default:
abort("Unknown option: " + args[0] + ".");
}
nextArg();
}
if (args.length > 0) {
abort("No arguments are allowed.");
}
Runner.run(benchmarks, runCount, {
Runner.run(benchmarks, runCount, options, {
readFile: function(file) {
return fs.readFileSync(__dirname + "/" + file, "utf8");
},