3 <script language="javascript">
4 var last = new Date(); // The last time we sampled the timer
5 var total_value = 0; // The sum of the intervals measured
6 var total_count = 0; // The count of the intervals measured
10 var current = new Date();
11 var ms = current - last;
16 // Display the interval output.
17 var output = document.getElementById('output');
18 output.innerHTML = ms + "ms";
20 // Display the average output.
21 var average = document.getElementById('average');
22 average.innerHTML = total_value / total_count + "ms";
24 // Get the new interval from the input.
25 var input = document.getElementById('input');
27 // If the interval has changed, reset our averages.
28 if (input.value != last_interval) {
32 last_interval = input.value;
35 setTimeout(fire, last_interval);
40 <body onload='setTimeout("fire()", 1)'>
42 <h1>Test JS setTimeout() speed</h1>
44 This page tests the frequency of setTimeout() in the browser.
45 Javascript applications use setTimeout() as a mechanism to 'yield'
46 to the browser so that the browser can repaint. Most browsers
47 implement a 15ms setTimeout() minimum. Use this to page to measure
48 setTimeout() lag and discover your browser's minimum interval.<P>
52 Desired ms to delay: <input id="input" type="text" value="1"><P>
56 instance: <div id="output"></div>
57 average: <div id="average"></div>