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..d92ee93db0b159135a82e64601241b12dd892dc5 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_deltas; |
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_deltas = []; |
} |
__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,44 @@ 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_deltas.length; |
+ |
+ for (var i = 0; i < N; i++) |
+ M += __t_deltas[i]; |
+ M = M / N; |
+ |
+ var V = 0.0; |
+ for (var i = 0; i < N; i++) { |
+ var v = __t_deltas[i] - M; |
+ V += v * v; |
+ } |
+ |
+ var S = Math.sqrt(V / (N - 1)); |
jbates
2011/11/11 23:43:46
(N - 1) should be N?
Justin Novosad
2011/11/14 16:08:42
Actually N-1 is correct for calculating unbiased s
|
+ // Report frame rate in terms of frames-per-second. However, |
+ // report error as an interval. Reporting it as 1/sigma amplifies |
+ // the noise and makes it seem higher than it actually is. |
+ // TODO(nduca): switch to a smarter measure of noise, possibly something |
+ // based on histogram-spikes or percentiles. |
Justin Novosad
2011/11/14 16:08:42
I think the right way to do it would be to compute
|
var R = new Object(); |
R.mean = 1000.0 / M; |
- R.sigma = R.mean - 1000.0 / (M + S); |
+ 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 +272,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. |
@@ -260,7 +285,7 @@ function __calc_results_total() { |
} |
function __update_fps() { |
- var t_now = new Date().getTime(); |
+ var t_now = __get_time(); |
if (window.__t_last) { |
var t_delta = t_now - __t_last; |
if (window.__t_est) { |
@@ -268,12 +293,11 @@ function __update_fps() { |
} else { |
__t_est = t_delta; |
} |
+ |
+ __t_deltas.push(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_last = t_now; |
} |
@@ -283,7 +307,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 +343,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; |
@@ -385,7 +409,7 @@ function __sched_update() { |
if (__advance_gesture()) |
__update_fps(); |
else |
- __t_last = new Date().getTime(); |
+ __t_last = __get_time(); |
} |
}, document.body); |
} |
@@ -419,7 +443,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(); |