Index: chrome/test/data/perf/frame_rate/head.js |
diff --git a/chrome/test/data/perf/frame_rate/head.js b/chrome/test/data/perf/frame_rate/head.js |
index 18f8485e27c6e9c3c2df24391d6d507b16b68a54..9c22c7a4c8dd0602b9c9bc826ab89ff562b76efc 100644 |
--- a/chrome/test/data/perf/frame_rate/head.js |
+++ b/chrome/test/data/perf/frame_rate/head.js |
@@ -41,12 +41,10 @@ var __old_title = ""; |
var __raf_is_live = false; |
var __raf; |
+var __t_start; |
var __t_last; |
var __t_est; |
-var __t_est_total; |
-var __t_est_squared_total; |
-var __t_count; |
-var __t_start; |
+var __t_frame_intervals; |
var __queued_gesture_functions; |
var __results; |
@@ -67,6 +65,10 @@ var __gesture_library = { |
{"time_ms":1, "y":0}, |
{"time_ms":5000, "y":0} |
], |
+ steady: [ |
+ {"time_ms":1, "y":0}, |
+ {"time_ms":500, "y":400} |
+ ], |
reading: [ |
{"time_ms":1, "y":0}, |
{"time_ms":842, "y":40}, |
@@ -180,22 +182,31 @@ function __gesture_stretch(gesture, stretch_factor) { |
// Gesture set to use for testing, initialized with default gesture set. |
// Redefine in test file to use a different set of gestures. |
var __gestures = { |
- none: __gesture_library["stationary"], |
- steady: __gesture_library["init"], |
- reading: __gesture_library["reading"], |
- mouse_wheel: __gesture_library["mouse_wheel"], |
- mac_fling: __gesture_library["mac_fling"], |
+ steady: __gesture_library["steady"], |
}; |
function __init_stats() { |
__t_last = undefined; |
__t_est = undefined; |
- __t_est_total = 0; |
- __t_est_squared_total = 0; |
- __t_count = 0; |
+ __t_frame_intervals = []; |
} |
__init_stats(); |
+var __cur_chrome_interval; |
+function __init_time() { |
+ if (chrome.Interval) { |
+ __cur_chrome_interval = new chrome.Interval(); |
+ __cur_chrome_interval.start(); |
+ } |
+} |
+__init_time(); |
+ |
+function __get_time() { |
+ if (__cur_chrome_interval) |
+ return __cur_chrome_interval.microseconds() / 1000; |
+ return new Date().getTime(); |
+} |
+ |
function __init_raf() { |
if ("requestAnimationFrame" in window) |
__raf = requestAnimationFrame; |
@@ -211,30 +222,39 @@ function __init_raf() { |
// No raf implementation available, fake it with 16ms timeouts |
__raf = function(callback, element) { |
setTimeout(callback, 16); |
- } |
+ }; |
} |
__init_raf(); |
function __calc_results() { |
- var M = __t_est_total / __t_count; |
- var X = __t_est_squared_total / __t_count; |
- var V = X - M * M; |
- var S = Math.sqrt(V); |
+ var M = 0.0; |
+ var N = __t_frame_intervals.length; |
+ |
+ for (var i = 0; i < N; i++) |
+ M += __t_frame_intervals[i]; |
+ M = M / N; |
+ |
+ var V = 0.0; |
+ for (var i = 0; i < N; i++) { |
+ var v = __t_frame_intervals[i] - M; |
+ V += v * v; |
+ } |
+ |
+ var S = Math.sqrt(V / (N - 1)); |
var R = new Object(); |
- R.mean = 1000.0 / M; |
- R.sigma = R.mean - 1000.0 / (M + S); |
+ R.mean = M; |
+ R.sigma = S; |
return R; |
} |
function __calc_results_total() { |
if (!__results) { |
- return; |
+ return {}; |
} |
var size = __results.gestures.length; |
var mean = 0; |
var variance = 0; |
- var sigma; |
// Remove any intial caching test(s). |
while (__results.means.length != size) { |
@@ -247,7 +267,7 @@ function __calc_results_total() { |
} |
mean /= size; |
variance /= size; |
- sigma = Math.sqrt(variance); |
+ var sigma = Math.sqrt(variance); |
var results = new Object(); |
// GTest expects a comma-separated string for lists. |
@@ -259,8 +279,8 @@ function __calc_results_total() { |
return results; |
} |
-function __update_fps() { |
- var t_now = new Date().getTime(); |
+function __record_frame_time() { |
+ var t_now = __get_time(); |
if (window.__t_last) { |
var t_delta = t_now - __t_last; |
if (window.__t_est) { |
@@ -268,12 +288,11 @@ function __update_fps() { |
} else { |
__t_est = t_delta; |
} |
- var fps = 1000.0 / __t_est; |
- document.title = "FPS: " + (fps | 0); |
- __t_est_total += t_delta; |
- __t_est_squared_total += t_delta * t_delta; |
- __t_count++; |
+ __t_frame_intervals.push(t_delta); |
+ |
+ var fps = 1000.0 / __t_est; |
+ document.title = "FPS: " + fps; |
} |
__t_last = t_now; |
} |
@@ -283,7 +302,7 @@ function __advance_gesture_recording() { |
var y = document.body.scrollTop; |
// Only add a gesture if the scroll position changes. |
if (__recording.length == 0 || y != __recording[__recording.length - 1].y) { |
- var time_ms = new Date().getTime() - __t_start; |
+ var time_ms = __get_time() - __t_start; |
__recording.push({ time_ms: time_ms, y: y }); |
return true; |
} |
@@ -319,7 +338,7 @@ function __create_gesture_function(gestures) { |
__stop(); |
return false; |
} |
- var time_cur = new Date().getTime() - __t_start; |
+ var time_cur = __get_time() - __t_start; |
if (time_cur <= gestures[i0].time_ms) |
return false; |
@@ -377,15 +396,15 @@ function __sched_update() { |
__raf_is_live = true; |
// In case __raf falls back to using setTimeout, we must schedule the next |
// update before rendering the current update to help maintain the |
- // regularity of update intervals. |
+ // regularity of update frame_intervals. |
__sched_update(); |
if (__running) { |
// Only update the FPS if a gesture movement occurs. Otherwise, the frame |
// rate average becomes inaccurate after any pause. |
if (__advance_gesture()) |
- __update_fps(); |
+ __record_frame_time(); |
else |
- __t_last = new Date().getTime(); |
+ __t_last = __get_time(); |
} |
}, document.body); |
} |
@@ -419,7 +438,7 @@ function __start(gesture_function) { |
__old_title = document.title; |
__advance_gesture = gesture_function; |
- __t_start = new Date().getTime(); |
+ __t_start = __get_time(); |
__running = true; |
if (!__raf_is_live && !__animation) { |
__sched_update(); |