Reduce resolution of performance.now.
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 00:29:55 +0000 (00:29 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 00:29:55 +0000 (00:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146531
rdar://problem/20116796

Reviewed by Simon Fraser.

Source/WebCore:

Test: http/tests/misc/webtiming-resolution.html

* page/Performance.cpp:
(WebCore::Performance::now):
Floor the time returned by performance.now to the nearest 5 microseconds.

LayoutTests:

* http/tests/misc/webtiming-resolution-expected.txt: Added.
* http/tests/misc/webtiming-resolution.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186208 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/misc/webtiming-resolution-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/webtiming-resolution.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Performance.cpp

index dd45700..654cdf2 100644 (file)
@@ -1,3 +1,14 @@
+2015-07-01  Alex Christensen  <achristensen@webkit.org>
+
+        Reduce resolution of performance.now.
+        https://bugs.webkit.org/show_bug.cgi?id=146531
+        rdar://problem/20116796
+
+        Reviewed by Simon Fraser.
+
+        * http/tests/misc/webtiming-resolution-expected.txt: Added.
+        * http/tests/misc/webtiming-resolution.html: Added.
+
 2015-07-01  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [iOS] Support bold and thin italicized system fonts
diff --git a/LayoutTests/http/tests/misc/webtiming-resolution-expected.txt b/LayoutTests/http/tests/misc/webtiming-resolution-expected.txt
new file mode 100644 (file)
index 0000000..b9a3dbc
--- /dev/null
@@ -0,0 +1,7 @@
+Verifies the minimum resolution is 5 microseconds.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS ((t1 - t0) / 0.005) % 1 < 1e-10 is true
+
diff --git a/LayoutTests/http/tests/misc/webtiming-resolution.html b/LayoutTests/http/tests/misc/webtiming-resolution.html
new file mode 100644 (file)
index 0000000..c6947c4
--- /dev/null
@@ -0,0 +1,20 @@
+<html>
+<head>
+<script src="../../js-test-resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Verifies the minimum resolution is 5 microseconds.");
+
+var t0 = performance.now();
+var t1 = performance.now();
+while (t0 == t1) {
+    t1 = performance.now();
+}
+shouldBe("((t1 - t0) / 0.005) % 1 < 1e-10", "true");
+
+</script>
+</body>
+</html>
index 0464ba3..122f736 100644 (file)
@@ -1,3 +1,17 @@
+2015-07-01  Alex Christensen  <achristensen@webkit.org>
+
+        Reduce resolution of performance.now.
+        https://bugs.webkit.org/show_bug.cgi?id=146531
+        rdar://problem/20116796
+
+        Reviewed by Simon Fraser.
+
+        Test: http/tests/misc/webtiming-resolution.html
+
+        * page/Performance.cpp:
+        (WebCore::Performance::now):
+        Floor the time returned by performance.now to the nearest 5 microseconds.
+
 2015-07-01  Eric Carlson  <eric.carlson@apple.com>
 
         [iOS] Build fix
index 6eefb37..fe226e8 100644 (file)
@@ -231,7 +231,9 @@ void Performance::webkitClearMeasures(const String& measureName)
 
 double Performance::now() const
 {
-    return 1000.0 * (WTF::monotonicallyIncreasingTime() - m_referenceTime);
+    double nowSeconds = WTF::monotonicallyIncreasingTime() - m_referenceTime;
+    const double resolutionSeconds = 0.000005;
+    return 1000.0 * floor(nowSeconds / resolutionSeconds) * resolutionSeconds;
 }
 
 } // namespace WebCore