Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit 22b9eb5

Browse files
committed
Add options to hardware latency test: add CPU load, pause requestAnimationFrame calls.
1 parent 914a40b commit 22b9eb5

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

html/hardware-latency-test.html

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
<meta http-equiv="x-ua-compatible" content="IE=edge">
44
<title>Web Latency Benchmark</title>
55
<link rel="stylesheet" href="latency-benchmark.css">
6+
<style>
7+
label { display: block; margin: 10px; }
8+
</style>
69

710
<h1>Web Latency Benchmark: Hardware test</h1>
811
<canvas id="testCanvas" width="400" height="400" style="border: 10px solid gray; margin-right: 20px; float: left"></canvas>
912
<a href="https://www.oculusvr.com/order/latency-tester/">Oculus Latency Tester</a> detected! Point it at the square on the left and press the test button, or 'T' on the keyboard, to run the test.
1013
<p>
11-
<label style="visibility:hidden"><input type="checkbox" id="cpuLoad"/> add CPU load</label><br/>
14+
<label><input type="range" min=0 max=40 value=0 id="cpuLoad"> <span id="cpuLoadText"></span> ms CPU load per frame</label>
15+
<label><input type="checkbox" id="stopCallingRaf"> Stop calling requestAnimationFrame between tests</label>
1216
<p>
1317
<div id="averageMs" style="font-size: 30px; color: white"></div>
1418
<div id="results"></div>
@@ -18,7 +22,17 @@ <h1>Web Latency Benchmark: Hardware test</h1>
1822
var averageMsDiv = document.getElementById('averageMs');
1923
var resultsDiv = document.getElementById('results');
2024
var cpuLoad = document.getElementById('cpuLoad');
25+
var cpuLoadText = document.getElementById('cpuLoadText');
26+
var stopCallingRaf = document.getElementById('stopCallingRaf');
2127
var testCanvas = document.getElementById('testCanvas');
28+
29+
var cpuLoadValue = 0;
30+
cpuLoad.oninput = function() {
31+
cpuLoadText.textContent = cpuLoad.value;
32+
cpuLoadValue = parseInt(cpuLoad.value);
33+
}
34+
cpuLoad.oninput();
35+
2236
var gl = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
2337
if (!gl) {
2438
resultsDiv.textContent = 'Failed to initialize WebGL. The test will not work.'
@@ -42,22 +56,30 @@ <h1>Web Latency Benchmark: Hardware test</h1>
4256
}
4357
};
4458

59+
var testRunning = false;
60+
var rafPending = true;
61+
4562
function draw() {
46-
requestAnimationFrame(draw);
63+
if (!stopCallingRaf.checked || testRunning) {
64+
requestAnimationFrame(draw);
65+
rafPending = true;
66+
} else {
67+
rafPending = false;
68+
}
4769
gl.clearColor(color[0], color[1], color[2], 1);
4870
gl.clear(gl.COLOR_BUFFER_BIT);
49-
if (cpuLoad.checked) {
50-
var startTime = Date.now();
51-
while(Date.now() - startTime < 14);
52-
}
71+
var startTime = Date.now();
72+
while(Date.now() - startTime < cpuLoadValue);
5373
}
5474
draw();
5575

5676
var results = [];
57-
var testRunning = false;
5877
function startTest() {
5978
if (testRunning) return;
6079
testRunning = true;
80+
if (!rafPending) {
81+
requestAnimationFrame(draw);
82+
}
6183
var request = new XMLHttpRequest();
6284
request.open('GET', 'http://localhost:5578/oculusLatencyTester?defeatCache=' + Math.random(), true);
6385
request.onreadystatechange = function() {

0 commit comments

Comments
 (0)