Add new timestamp option
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2016 03:26:24 +0000 (03:26 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2016 03:26:24 +0000 (03:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159006

Reviewed by Dean Jackson.

Add a new option to take timestamps from the rAF callback.

* Animometer/developer.html: Added option.
* Animometer/tests/resources/main.js:
(Benchmark): Fall back to using the rAF timestamp if performance.now()
is not available.
(Benchmark._animateLoop): Update how timestamp is set. Prefer to use
local var instead of accessing private var.

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

PerformanceTests/Animometer/developer.html
PerformanceTests/Animometer/tests/resources/main.js
PerformanceTests/ChangeLog

index 9c14e0f..1a33c79 100644 (file)
@@ -70,7 +70,8 @@
                                 <li>
                                     <h3>Time measurement method:</h3>
                                     <ul>
-                                        <li><label><input name="time-measurement" type="radio" value="performance" checked> <code>performance.now()</code></label></li>
+                                        <li><label><input name="time-measurement" type="radio" value="performance" checked> <code>performance.now()</code> (if available)</label></li>
+                                        <li><label><input name="time-measurement" type="radio" value="raf"> <code>requestAnimationFrame()</code> timestamp</label></li>
                                         <li><label><input name="time-measurement" type="radio" value="date"> <code>Date.now()</code></label></li>
                                     </ul>
                                 </li>
index 29bb158..b9776d5 100644 (file)
@@ -832,7 +832,13 @@ Benchmark = Utilities.createClass(
         switch (options["time-measurement"])
         {
         case "performance":
-            this._getTimestamp = performance.now.bind(performance);
+            if (window.performance && window.performance.now)
+                this._getTimestamp = performance.now.bind(performance);
+            else
+                this._getTimestamp = null;
+            break;
+        case "raf":
+            this._getTimestamp = null;
             break;
         case "date":
             this._getTimestamp = Date.now;
@@ -879,7 +885,7 @@ Benchmark = Utilities.createClass(
     {
         return this.waitUntilReady().then(function() {
             this._finishPromise = new SimplePromise;
-            this._previousTimestamp = this._getTimestamp();
+            this._previousTimestamp = undefined;
             this._didWarmUp = false;
             this._stage.tune(this._controller.initialComplexity - this._stage.complexity());
             this._animateLoop();
@@ -895,21 +901,24 @@ Benchmark = Utilities.createClass(
         return promise;
     },
 
-    _animateLoop: function()
+    _animateLoop: function(timestamp)
     {
-        this._currentTimestamp = this._getTimestamp();
+        timestamp = (this._getTimestamp && this._getTimestamp()) || timestamp;
+        this._currentTimestamp = timestamp;
 
-        if (this._controller.shouldStop(this._currentTimestamp)) {
+        if (this._controller.shouldStop(timestamp)) {
             this._finishPromise.resolve(this._controller.results());
             return;
         }
 
         if (!this._didWarmUp) {
-            if (this._currentTimestamp - this._previousTimestamp >= 100) {
+            if (!this._previousTimestamp)
+                this._previousTimestamp = timestamp;
+            else if (timestamp - this._previousTimestamp >= 100) {
                 this._didWarmUp = true;
-                this._startTimestamp = this._currentTimestamp;
-                this._controller.start(this._currentTimestamp, this._stage);
-                this._previousTimestamp = this._currentTimestamp;
+                this._startTimestamp = timestamp;
+                this._controller.start(timestamp, this._stage);
+                this._previousTimestamp = timestamp;
             }
 
             this._stage.animate(0);
@@ -917,9 +926,9 @@ Benchmark = Utilities.createClass(
             return;
         }
 
-        this._controller.update(this._currentTimestamp, this._stage);
-        this._stage.animate(this._currentTimestamp - this._previousTimestamp);
-        this._previousTimestamp = this._currentTimestamp;
+        this._controller.update(timestamp, this._stage);
+        this._stage.animate(timestamp - this._previousTimestamp);
+        this._previousTimestamp = timestamp;
         requestAnimationFrame(this._animateLoop);
     }
 });
index 55957f1..d7306d5 100644 (file)
@@ -1,5 +1,21 @@
 2016-06-21  Jon Lee  <jonlee@apple.com>
 
+        Add new timestamp option
+        https://bugs.webkit.org/show_bug.cgi?id=159006
+
+        Reviewed by Dean Jackson.
+
+        Add a new option to take timestamps from the rAF callback.
+
+        * Animometer/developer.html: Added option.
+        * Animometer/tests/resources/main.js:
+        (Benchmark): Fall back to using the rAF timestamp if performance.now()
+        is not available.
+        (Benchmark._animateLoop): Update how timestamp is set. Prefer to use
+        local var instead of accessing private var.
+
+2016-06-21  Jon Lee  <jonlee@apple.com>
+
         Improvements to Animometer benchmark
         https://bugs.webkit.org/show_bug.cgi?id=157738