diff --git a/benchmark/index.css b/benchmark/index.css index a54bbbf..a4ebb44 100644 --- a/benchmark/index.css +++ b/benchmark/index.css @@ -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; } diff --git a/benchmark/index.html b/benchmark/index.html index 4b68f18..dc1e6cc 100644 --- a/benchmark/index.html +++ b/benchmark/index.html @@ -11,6 +11,8 @@
times + +
diff --git a/benchmark/index.js b/benchmark/index.js index 547060d..e8daa34 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -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"); } }); diff --git a/benchmark/run b/benchmark/run index 254915c..4aa519e 100755 --- a/benchmark/run +++ b/benchmark/run @@ -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 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"); }, diff --git a/benchmark/runner.js b/benchmark/runner.js index 89d05bc..ea0ddc0 100644 --- a/benchmark/runner.js +++ b/benchmark/runner.js @@ -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;