• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3<head>
4<meta charset="utf-8" />
5<title>window.performance.now should not enable timing attacks</title>
6<link rel="author" title="W3C" href="http://www.w3.org/" />
7<link rel="help" href="http://w3c.github.io/hr-time/#privacy-security"/>
8<script src="/resources/testharness.js"></script>
9<script src="/resources/testharnessreport.js"></script>
10<script>
11test(function() {
12  function check_resolutions(times, length) {
13    var end = length - 2;
14
15    // we compare each value with the following ones
16    for (var i = 0; i < end; i++) {
17      var h1 = times[i];
18      for (var j = i+1; j < end; j++) {
19        var h2 = times[j];
20        var diff = h2 - h1;
21        assert_true((diff === 0) || ((diff * 1000) >= 5),
22          "Differences smaller than 5 microseconds: " + diff);
23      }
24    }
25    return true;
26  }
27
28  var times = new Array(10);
29  var index = 0;
30  var hrt1, hrt2, hrt;
31
32  // rapid firing of performance.now
33  hrt1 = performance.now();
34  hrt2 = performance.now();
35  times[index++] = hrt1;
36  times[index++] = hrt2;
37
38  // ensure that we get performance.now() to return a different value
39  do {
40    hrt = performance.now();
41    times[index++] = hrt;
42  } while ((hrt - hrt1) === 0);
43
44  assert_true(check_resolutions(times, index), 'Difference should be at least 5 microseconds.');
45}, 'The recommended minimum resolution of the Performance interface has been set to 5 microseconds');
46</script>
47</head>
48<body>
49<h1>Description</h1>
50<p>The recommended minimum resolution of the Performance interface should be set to 5 microseconds.</p>
51
52<div id="log"></div>
53
54</body>
55</html>
56