summaryrefslogtreecommitdiff
path: root/chromium/webkit/data/test_shell/js/timers.html
blob: 2841e2f2d45fb22f98963ea16342ffc692d5eb41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<head>
<script language="javascript">
var last = new Date();    // The last time we sampled the timer
var total_value = 0;      // The sum of the intervals measured
var total_count = 0;      // The count of the intervals measured
var last_interval = 1;
function fire() {

  var current = new Date();
  var ms = current - last;

  total_value += ms;
  total_count++;

  // Display the interval output.
  var output = document.getElementById('output');
  output.innerHTML = ms + "ms";

  // Display the average output.
  var average = document.getElementById('average');
  average.innerHTML = total_value / total_count + "ms";

  // Get the new interval from the input.
  var input = document.getElementById('input');

  // If the interval has changed, reset our averages.
  if (input.value != last_interval) {
    total_value = 0;
    total_count = 0;
  }
  last_interval = input.value;

  last = new Date();
  setTimeout(fire, last_interval);
}
</script>
</head>

<body onload='setTimeout("fire()", 1)'>

<h1>Test JS setTimeout() speed</h1>

This page tests the frequency of setTimeout() in the browser.
Javascript applications use setTimeout() as a mechanism to 'yield'
to the browser so that the browser can repaint.  Most browsers
implement a 15ms setTimeout() minimum.  Use this to page to measure
setTimeout() lag and discover your browser's minimum interval.<P>

<hr>

Desired ms to delay: <input id="input" type="text" value="1"><P>

Measured delay:<br>
<ul>
instance: <div id="output"></div>
average: <div id="average"></div>
</ul>

</body>
</html>