Improving benchmark: 1) show average time 2) allow to disable animation

This commit is contained in:
Alexey Andreev 2017-02-07 22:21:04 +03:00
parent 9271d71906
commit 21ae63038e
2 changed files with 23 additions and 1 deletions

View File

@ -28,16 +28,21 @@ import org.teavm.jso.canvas.CanvasRenderingContext2D;
import org.teavm.jso.dom.html.HTMLCanvasElement;
import org.teavm.jso.dom.html.HTMLDocument;
import org.teavm.jso.dom.html.HTMLElement;
import org.teavm.jso.dom.html.HTMLInputElement;
import org.teavm.samples.benchmark.shared.Scene;
public final class BenchmarkStarter {
private static HTMLDocument document = Window.current().getDocument();
private static HTMLCanvasElement canvas = (HTMLCanvasElement) document.getElementById("benchmark-canvas");
private static HTMLElement resultTableBody = document.getElementById("result-table-body");
private static HTMLInputElement displayAnimationCheckbox =
document.getElementById("display-animation-checkbox").cast();
private static HTMLElement averageTime = document.getElementById("average-time");
private static Scene scene = new Scene();
private static int currentSecond;
private static long startMillisecond;
private static double timeSpentCalculating;
private static double totalTime;
private BenchmarkStarter() {
}
@ -62,11 +67,18 @@ public final class BenchmarkStarter {
row.appendChild(timeCell);
timeCell.appendChild(document.createTextNode(String.valueOf(timeSpentCalculating)));
totalTime += timeSpentCalculating;
timeSpentCalculating = 0;
currentSecond = second;
averageTime.withText(String.valueOf(Math.round(totalTime / second)));
}
timeSpentCalculating += end - start;
render();
if (displayAnimationCheckbox.isChecked()) {
render();
}
Window.setTimeout(() -> makeStep(), scene.timeUntilNextStep());
}

View File

@ -26,6 +26,10 @@
<div>
<canvas id="benchmark-canvas" width="600" height="600"></canvas>
</div>
<div>
<input type="checkbox" id="display-animation-checkbox" checked>
<label for="display-animation-checkbox">display animation</label>
</div>
<table>
<thead>
<tr>
@ -35,6 +39,12 @@
</thead>
<tbody id="result-table-body">
</tbody>
<tfoot>
<tr>
<th>Average</th>
<td id="average-time"></td>
<tr>
</tfoot>
</table>
</body>
</html>