| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="/js-test-resources/js-test.js"></script> | 3 <script src="/js-test-resources/js-test.js"></script> |
| 4 </head> | 4 </head> |
| 5 <body> | 5 <body> |
| 6 <p id="description"></p> | 6 <p id="description"></p> |
| 7 <div id="console"></div> | 7 <div id="console"></div> |
| 8 <script> | 8 <script> |
| 9 description("Verifies the minimum resolution is 5 microseconds."); | 9 description("Verifies the minimum resolution is 5 microseconds."); |
| 10 | 10 |
| 11 var t0 = performance.now(); | 11 function testTimeResolution(highResTimeFunc) { |
| 12 var t1 = performance.now(); | 12 var t0 = highResTimeFunc(); |
| 13 while (t0 == t1) { | 13 var t1 = highResTimeFunc(); |
| 14 t1 = performance.now(); | 14 while (t0 == t1) { |
| 15 t1 = highResTimeFunc(); |
| 16 } |
| 17 |
| 18 var expectedResolutionMilliseconds = 0.005; |
| 19 var integerMultipleOfResolution = (t1 - t0) / expectedResolutionMilliseconds
; |
| 20 shouldBeNearZeroOrOne = integerMultipleOfResolution % 1; |
| 21 shouldBe("shouldBeNearZeroOrOne < 1e-10 || Math.abs(shouldBeNearZeroOrOne -
1) < 1e-10", "true"); |
| 15 } | 22 } |
| 16 | 23 |
| 17 var expectedResolutionMilliseconds = 0.005; | 24 function timeByPerformanceNow() { |
| 18 var integerMultipleOfResolution = (t1 - t0) / expectedResolutionMilliseconds; | 25 return performance.now(); |
| 19 var shouldBeNearZeroOrOne = integerMultipleOfResolution % 1; | 26 } |
| 20 shouldBe("shouldBeNearZeroOrOne < 1e-10 || Math.abs(shouldBeNearZeroOrOne - 1) <
1e-10", "true"); | |
| 21 | 27 |
| 28 function timeByUserTiming() { |
| 29 performance.mark('timer'); |
| 30 var t = performance.getEntriesByName('timer')[0].startTime; |
| 31 performance.clearMarks('timer'); |
| 32 return t; |
| 33 } |
| 34 |
| 35 testTimeResolution(timeByPerformanceNow); |
| 36 testTimeResolution(timeByUserTiming); |
| 22 </script> | 37 </script> |
| 23 </body> | 38 </body> |
| 24 </html> | 39 </html> |
| OLD | NEW |