Make benchmark suite support |trackLineAndColumn| option

Both the browser and the command-line version of the benchmark suite
runner now allow users to specify a value of the |trackLineAndColumn|
option. In case of the command-line version this required a minor CLI
redesign.
redux
David Majda 12 years ago
parent 58cc5b739d
commit 0865e9e51a

@ -30,4 +30,5 @@ a, a:visited { color: #3d586c; }
background-color: #f0f0f0;
}
#options #run-count { width: 3em; }
#options #track-line-and-column { margin-left: 2em; }
#options #run { width: 5em; margin-left: 2em; }

@ -11,6 +11,8 @@
<div id="options">
<label for="run-count">Run each test</label>
<input type="text" id="run-count" value="10"> times
<input type="checkbox" id="track-line-and-column">
<label for="track-line-and-column">Track line and column</label>
<input type="button" id="run" value="Run">
</div>

@ -62,7 +62,11 @@ $("#run").click(function() {
return;
}
Runner.run(benchmarks, runCount, {
var options = {
trackLineAndColumn: $("#track-line-and-column").is(":checked")
};
Runner.run(benchmarks, runCount, options, {
readFile: function(file) {
return $.ajax({
type: "GET",
@ -101,7 +105,7 @@ $("#run").click(function() {
},
start: function() {
$("#run-count, #run").attr("disabled", "disabled");
$("#run-count, #track-line-and-column, #run").attr("disabled", "disabled");
resultsTable.show();
$("#results-table tr").slice(1).remove();
@ -118,7 +122,7 @@ $("#run").click(function() {
$.scrollTo("max", { axis: "y", duration: 500 });
$("#run-count, #run").removeAttr("disabled");
$("#run-count, #track-line-and-column, #run").removeAttr("disabled");
}
});

@ -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");
},

@ -1,5 +1,5 @@
Runner = {
run: function(benchmarks, runCount, callbacks) {
run: function(benchmarks, runCount, options, callbacks) {
/* Queue */
@ -52,7 +52,8 @@ Runner = {
callbacks.benchmarkStart(benchmarks[i]);
state.parser = PEG.buildParser(
callbacks.readFile("../examples/" + benchmarks[i].id + ".pegjs")
callbacks.readFile("../examples/" + benchmarks[i].id + ".pegjs"),
options
);
state.benchmarkInputSize = 0;
state.benchmarkParseTime = 0;

Loading…
Cancel
Save