3 # Process the raw output from benchmark.sh into Javascript-ified HTML.
14 if (/^(.*)(#.*): ([\d\.]+)$/) {
15 push @presets, $1 unless defined $presets{$1};
16 push @{$presets{$1}}, $3;
17 $maxval = $3 if $maxval < $3;
25 <meta http-equiv="Content-Type" content="text/html; charset=ASCII" />
26 <title>Puzzle generation-time benchmarks</title>
27 <script type="text/javascript">
29 function choose_scale_ticks(scale) {
30 var nscale = 1, j = 0, factors = [2,2.5,2];
31 while (scale / nscale > 20) {
33 j = (j+1) % factors.length;
37 function initPlots() {
38 var canvases = document.getElementsByTagName('canvas');
39 for (var i = 0; i < canvases.length; i++) {
40 var canvas = canvases[i];
41 var scale = eval(canvas.getAttribute("data-scale"));
42 var add = 20.5, mult = (canvas.width - 2*add) / scale;
43 var data = eval(canvas.getAttribute("data-points"));
44 var ctx = canvas.getContext('2d');
45 ctx.lineWidth = '1px';
46 ctx.lineCap = 'round';
47 ctx.lineJoin = 'round';
48 ctx.strokeStyle = ctx.fillStyle = '#000000';
49 if (data === "scale") {
51 ctx.font = "16px sans-serif";
52 ctx.textAlign = "center";
53 ctx.textBaseline = "alphabetic";
54 var nscale = choose_scale_ticks(scale);
55 for (var x = 0; x <= scale; x += nscale) {
57 ctx.moveTo(add+mult*x, canvas.height);
58 ctx.lineTo(add+mult*x, canvas.height - 3);
60 ctx.fillText(x + "s", add+mult*x, canvas.height - 6);
64 function quantile(x) {
65 var n = (data.length * x) | 0;
66 return (data[n-1] + data[n]) / 2;
69 var q1 = quantile(0.25), q2 = quantile(0.5), q3 = quantile(0.75);
71 var top = 0.5, bot = canvas.height - 1.5, mid = (top+bot)/2;
72 var wlo = null, whi = null; // whisker ends
74 ctx.strokeStyle = '#bbbbbb';
75 var nscale = choose_scale_ticks(scale);
76 for (var x = 0; x <= scale; x += nscale) {
78 ctx.moveTo(add+mult*x, 0);
79 ctx.lineTo(add+mult*x, canvas.height);
82 ctx.strokeStyle = '#000000';
86 if (x >= q1 - 1.5 * iqr && x <= q3 + 1.5 * iqr) {
87 if (wlo === null || wlo > x)
89 if (whi === null || whi < x)
93 ctx.arc(add+mult*x, mid, 2, 0, 2*Math.PI);
95 if (x >= q1 - 3 * iqr && x <= q3 + 3 * iqr)
103 ctx.moveTo(add+mult*q1, top);
104 ctx.lineTo(add+mult*q3, top);
105 ctx.lineTo(add+mult*q3, bot);
106 ctx.lineTo(add+mult*q1, bot);
110 ctx.moveTo(add+mult*q2, top);
111 ctx.lineTo(add+mult*q2, bot);
114 ctx.moveTo(add+mult*q1, mid);
115 ctx.lineTo(add+mult*wlo, mid);
116 ctx.moveTo(add+mult*wlo, top);
117 ctx.lineTo(add+mult*wlo, bot);
120 ctx.moveTo(add+mult*q3, mid);
121 ctx.lineTo(add+mult*whi, mid);
122 ctx.moveTo(add+mult*whi, top);
123 ctx.lineTo(add+mult*whi, bot);
128 document.getElementById('sort_orig').onclick = function() {
130 return parseFloat(e.getAttribute("data-index"));
133 document.getElementById('sort_median').onclick = function() {
135 return -parseFloat(e.getAttribute("data-median"));
138 document.getElementById('sort_mean').onclick = function() {
140 return -parseFloat(e.getAttribute("data-mean"));
144 function sort(keyfn) {
145 var rows = document.getElementsByTagName("tr");
147 for (var i = 0; i < rows.length; i++)
149 trs.sort(function(a,b) {
152 return akey < bkey ? -1 : akey > bkey ? +1 : 0;
154 var parent = trs[0].parentElement;
155 for (var i = 0; i < trs.length; i++)
156 parent.removeChild(trs[i]);
157 for (var i = 0; i < trs.length; i++)
158 parent.appendChild(trs[i]);
163 <body onLoad="initPlots();">
164 <h1 align=center>Puzzle generation-time benchmarks</h1>
166 <button id="sort_orig">Original</button>
167 <button id="sort_median">Median</button>
168 <button id="sort_mean">Mean</button>
170 <tr><th>Preset</th><td><canvas width=700 height=30 data-points='"scale"' data-scale="$maxval"></td></tr>
174 for my $preset (@presets) {
175 my @data = sort { $a <=> $b } @{$presets{$preset}};
176 my $median = ($#data % 2 ?
177 ($data[($#data-1)/2]+$data[($#data+1)/2])/2 :
179 my $mean = 0; map { $mean += $_ } @data; $mean /= @data;
180 print "<tr data-index=\"$index\" data-mean=\"$mean\" data-median=\"$median\"><td>", &escape($preset), "</td><td><canvas width=700 height=15 data-points=\"[";
181 print join ",", @data;
182 print "]\" data-scale=\"$maxval\"></td></tr>\n";
193 $text =~ s/&/&/g;