Debian Codegraph @

benchmark/index.js

raw symbols SCIP
1 /* eslint-env browser, jquery */
2 /* global benchmarks, Runner */
3
4 $("#run").click(function() {
5 "use strict";
6
7 /* Results Table Manipulation */
8
9 var resultsTable = $("#results-table");
10
11 function appendHeading(heading) {
12 resultsTable.append(
13 "<tr class='heading'><th colspan='4'>" + heading + "</th></tr>"
14 );
15 }
16
17 function appendResult(klass, title, url, inputSize, parseTime) {
18 var KB = 1024,
19 MS_IN_S = 1000;
20
21 resultsTable.append(
22 "<tr class='" + klass + "'>"
23 + "<td class='title'>"
24 + (url !== null ? "<a href='" + url + "'>" : "")
25 + title
26 + (url !== null ? "</a>" : "")
27 + "</td>"
28 + "<td class='input-size'>"
29 + "<span class='value'>"
30 + (inputSize / KB).toFixed(2)
31 + "</span>"
32 + "&nbsp;<span class='unit'>kB</span>"
33 + "</td>"
34 + "<td class='parse-time'>"
35 + "<span class='value'>"
36 + parseTime.toFixed(2)
37 + "</span>"
38 + "&nbsp;<span class='unit'>ms</span>"
39 + "</td>"
40 + "<td class='parse-speed'>"
41 + "<span class='value'>"
42 + ((inputSize / KB) / (parseTime / MS_IN_S)).toFixed(2)
43 + "</span>"
44 + "&nbsp;<span class='unit'>kB/s</span>"
45 + "</td>"
46 + "</tr>"
47 );
48 }
49
50 /* Main */
51
52 /*
53 * Each input is parsed multiple times and the results are averaged. We
54 * do this for two reasons:
55 *
56 * 1. To warm up the interpreter (PEG.js-generated parsers will be
57 * most likely used repeatedly, so it makes sense to measure
58 * performance after warming up).
59 *
60 * 2. To minimize random errors.
61 */
62
63 var runCount = parseInt($("#run-count").val(), 10),
64 options = {
65 cache: $("#cache").is(":checked"),
66 optimize: $("#optimize").val()
67 };
68
69 if (isNaN(runCount) || runCount <= 0) {
70 alert("Number of runs must be a positive integer.");
71 return;
72 }
73
74 Runner.run(benchmarks, runCount, options, {
75 readFile: function(file) {
76 return $.ajax({
77 type: "GET",
78 url: file,
79 dataType: "text",
80 async: false
81 }).responseText;
82 },
83
84 testStart: function() {
85 /* Nothing to do. */
86 },
87
88 testFinish: function(benchmark, test, inputSize, parseTime) {
89 appendResult(
90 "individual",
91 test.title,
92 benchmark.id + "/" + test.file,
93 inputSize,
94 parseTime
95 );
96 },
97
98 benchmarkStart: function(benchmark) {
99 appendHeading(benchmark.title);
100 },
101
102 benchmarkFinish: function(benchmark, inputSize, parseTime) {
103 appendResult(
104 "benchmark-total",
105 benchmark.title + " total",
106 null,
107 inputSize,
108 parseTime
109 );
110 },
111
112 start: function() {
113 $("#run-count, #cache, #run").attr("disabled", "disabled");
114
115 resultsTable.show();
116 $("#results-table tr").slice(1).remove();
117 },
118
119 finish: function(inputSize, parseTime) {
120 appendResult(
121 "total",
122 "Total",
123 null,
124 inputSize,
125 parseTime
126 );
127
128 $.scrollTo("max", { axis: "y", duration: 500 });
129
130 $("#run-count, #cache, #run").removeAttr("disabled");
131 }
132 });
133
134 });
135
136 $(document).ready(function() {
137 "use strict";
138
139 $("#run").focus();
140 });