Benchmark: Users can specify the number of runs

redux
David Majda 14 years ago
parent 4cae3f9b48
commit 647e7be1fd

@ -16,6 +16,7 @@
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; }
@ -27,11 +28,26 @@
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; }
</style>
</head>
<body>
<h1>PEG.js Benchmark Suite</h1>
<div id="options">
<label for="run-count">Run each test</label>
<input type="text" id="run-count" value="10"> times
<input type="button" id="run" value="Run">
</div>
<table id="results-table">
<tr class="columns">
<th>Test</th>
@ -39,6 +55,9 @@
<th>Average Parse Time</th>
<th>Average Parse Speed</th>
</tr>
<tr>
<td class="no-results" colspan="4">No results available yet.</td>
</tr>
</table>
<script src="../lib/compiler.js"></script>
@ -46,18 +65,6 @@
<script src="../vendor/jquery/jquery.js"></script>
<script src="../vendor/jquery.scrollto/jquery.scrollTo.js"></script>
<script>
/*
* Each input is parsed |RUNS| 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 RUNS = 10;
var benchmarks = [
{
id: "json",
@ -97,7 +104,7 @@
}
];
$(document).ready(function() {
$("#run").click(function() {
var resultsTable = $("#results-table");
function appendHeading(heading) {
@ -148,6 +155,27 @@
}).responseText;
}
/*
* 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;
}
$("#run-count, #run").attr("disabled", "disabled");
resultsTable.show();
$("#results-table tr").slice(1).remove();
var totalInputSize = 0;
var totalParseTime = 0;
@ -169,12 +197,12 @@
var input = get(url);
var parseTime = 0;
for (var k = 0; k < RUNS; k++) {
for (var k = 0; k < runCount; k++) {
var t = (new Date).getTime();
parser.parse(input);
parseTime += (new Date).getTime() - t;
}
var averageParseTime = parseTime / RUNS;
var averageParseTime = parseTime / runCount;
appendResult(
"individual",
@ -203,6 +231,12 @@
appendResult("total", "Total", null, totalInputSize, totalParseTime);
$.scrollTo("max", { axis: "y", duration: 500 });
$("#run-count, #run").removeAttr("disabled");
});
$(document).ready(function() {
$("#run").focus();
});
</script>
</body>

Loading…
Cancel
Save