mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Improving benchmark: 1) show average time 2) allow to disable animation
This commit is contained in:
parent
9271d71906
commit
21ae63038e
|
@ -28,16 +28,21 @@ import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||||
import org.teavm.jso.dom.html.HTMLDocument;
|
import org.teavm.jso.dom.html.HTMLDocument;
|
||||||
import org.teavm.jso.dom.html.HTMLElement;
|
import org.teavm.jso.dom.html.HTMLElement;
|
||||||
|
import org.teavm.jso.dom.html.HTMLInputElement;
|
||||||
import org.teavm.samples.benchmark.shared.Scene;
|
import org.teavm.samples.benchmark.shared.Scene;
|
||||||
|
|
||||||
public final class BenchmarkStarter {
|
public final class BenchmarkStarter {
|
||||||
private static HTMLDocument document = Window.current().getDocument();
|
private static HTMLDocument document = Window.current().getDocument();
|
||||||
private static HTMLCanvasElement canvas = (HTMLCanvasElement) document.getElementById("benchmark-canvas");
|
private static HTMLCanvasElement canvas = (HTMLCanvasElement) document.getElementById("benchmark-canvas");
|
||||||
private static HTMLElement resultTableBody = document.getElementById("result-table-body");
|
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 Scene scene = new Scene();
|
||||||
private static int currentSecond;
|
private static int currentSecond;
|
||||||
private static long startMillisecond;
|
private static long startMillisecond;
|
||||||
private static double timeSpentCalculating;
|
private static double timeSpentCalculating;
|
||||||
|
private static double totalTime;
|
||||||
|
|
||||||
private BenchmarkStarter() {
|
private BenchmarkStarter() {
|
||||||
}
|
}
|
||||||
|
@ -62,11 +67,18 @@ public final class BenchmarkStarter {
|
||||||
row.appendChild(timeCell);
|
row.appendChild(timeCell);
|
||||||
timeCell.appendChild(document.createTextNode(String.valueOf(timeSpentCalculating)));
|
timeCell.appendChild(document.createTextNode(String.valueOf(timeSpentCalculating)));
|
||||||
|
|
||||||
|
totalTime += timeSpentCalculating;
|
||||||
timeSpentCalculating = 0;
|
timeSpentCalculating = 0;
|
||||||
currentSecond = second;
|
currentSecond = second;
|
||||||
|
|
||||||
|
averageTime.withText(String.valueOf(Math.round(totalTime / second)));
|
||||||
}
|
}
|
||||||
timeSpentCalculating += end - start;
|
timeSpentCalculating += end - start;
|
||||||
|
|
||||||
|
if (displayAnimationCheckbox.isChecked()) {
|
||||||
render();
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
Window.setTimeout(() -> makeStep(), scene.timeUntilNextStep());
|
Window.setTimeout(() -> makeStep(), scene.timeUntilNextStep());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
<div>
|
<div>
|
||||||
<canvas id="benchmark-canvas" width="600" height="600"></canvas>
|
<canvas id="benchmark-canvas" width="600" height="600"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="checkbox" id="display-animation-checkbox" checked>
|
||||||
|
<label for="display-animation-checkbox">display animation</label>
|
||||||
|
</div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -35,6 +39,12 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="result-table-body">
|
<tbody id="result-table-body">
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Average</th>
|
||||||
|
<td id="average-time"></td>
|
||||||
|
<tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user