diff --git a/benchmark/index.css b/benchmark/index.css new file mode 100644 index 0000000..a54bbbf --- /dev/null +++ b/benchmark/index.css @@ -0,0 +1,33 @@ +body { + margin: 2em 4em; + font-family: "Trebuchet MS", lucida, sans-serif; + line-height: 1.5; + color: black; background-color: white; +} + +h1 { margin: 0 0 .75em 0; text-align: center; font-size: 200%; } + +table { width: 48em; margin: 0 auto; border-spacing: 0; border-collapse: collapse; } +table td, table th { border: 1px solid silver; padding: .25em 1em; } +table td .unit { font-size: 75%; color: gray; } +table td.no-results { padding: 1em; text-align: center; } +table td.input-size { text-align: right; } +table td.parse-time { text-align: right; } +table td.parse-speed { text-align: right; } +table tr.columns th { border-color: #404040; color: white; background-color: #404040; } +table tr.heading th { background-color: #e0e0e0; } +table tr.benchmark-total td { font-weight: bold; } +table tr.total td { background-color: #ffff80; font-weight: bold; } +table tr.total td .unit { color: #808000; } +table tr.total td.parse-speed .value { font-size: 175%; } + +a, a:visited { color: #3d586c; } + +#options { + width: 46em; + margin: 2em auto; border-radius: .5em; -moz-border-radius: .5em; padding: .5em 1em; + text-align: center; + background-color: #f0f0f0; +} +#options #run-count { width: 3em; } +#options #run { width: 5em; margin-left: 2em; } diff --git a/benchmark/index.html b/benchmark/index.html index 52f598f..4b68f18 100644 --- a/benchmark/index.html +++ b/benchmark/index.html @@ -3,41 +3,7 @@ PEG.js Benchmark Suite - +

PEG.js Benchmark Suite

@@ -65,137 +31,6 @@ - + diff --git a/benchmark/index.js b/benchmark/index.js new file mode 100644 index 0000000..e87e0fe --- /dev/null +++ b/benchmark/index.js @@ -0,0 +1,129 @@ +$("#run").click(function() { + + /* Results Table Manipulation */ + + var resultsTable = $("#results-table"); + + function appendHeading(heading) { + resultsTable.append( + "" + heading + "" + ); + } + + function appendResult(klass, title, url, inputSize, parseTime) { + var KB = 1024; + var MS_IN_S = 1000; + + resultsTable.append( + "" + + "" + + (url !== null ? "" : "") + + title + + (url !== null ? "" : "") + + "" + + "" + + "" + + (inputSize / KB).toFixed(2) + + "" + + " kB" + + "" + + "" + + "" + + parseTime.toFixed(2) + + "" + + " ms" + + "" + + "" + + "" + + ((inputSize / KB) / (parseTime / MS_IN_S)).toFixed(2) + + "" + + " kB/s" + + "" + + "" + ); + } + + /* Main */ + + /* + * Each input is parsed multiple times and the results are averaged. We + * do this for two reasons: + * + * 1. To warm up the interpreter (PEG.js-generated parsers will be + * most likely used repeatedly, so it makes sense to measure + * performance after warming up). + * + * 2. To minimize random errors. + */ + + var runCount = parseInt($("#run-count").val()); + if (isNaN(runCount) || runCount <= 0) { + alert("Number of runs must be a positive integer."); + return; + } + + Runner.run(benchmarks, runCount, { + readFile: function(file) { + return $.ajax({ + type: "GET", + url: file, + dataType: "text", + async: false + }).responseText; + }, + + testStart: function(benchmark, test) { + /* Nothing to do. */ + }, + + testFinish: function(benchmark, test, inputSize, parseTime) { + appendResult( + "individual", + test.title, + benchmark.id + "/" + test.file, + inputSize, + parseTime + ); + }, + + benchmarkStart: function(benchmark) { + appendHeading(benchmark.title); + }, + + benchmarkFinish: function(benchmark, inputSize, parseTime) { + appendResult( + "benchmark-total", + benchmark.title + " total", + null, + inputSize, + parseTime + ); + }, + + start: function() { + $("#run-count, #run").attr("disabled", "disabled"); + + resultsTable.show(); + $("#results-table tr").slice(1).remove(); + }, + + finish: function(inputSize, parseTime) { + appendResult( + "total", + "Total", + null, + inputSize, + parseTime + ); + + $.scrollTo("max", { axis: "y", duration: 500 }); + + $("#run-count, #run").removeAttr("disabled"); + } + }); + +}); + +$(document).ready(function() { + $("#run").focus(); +});