Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var __running = false; | |
| 6 var __old_title = ""; | |
| 7 var __scroll_by = 300; | |
| 8 | |
|
nduca
2011/05/22 04:33:41
Eg, on Nytimes (www/~nduca/test/perf/nytimes.html)
| |
| 9 var __t_last; | |
| 10 var __t_est; | |
| 11 var __t_est_total; | |
| 12 var __t_est_squared_total; | |
| 13 var __t_count; | |
| 14 | |
| 15 function __init_stats() { | |
| 16 __t_last = undefined; | |
| 17 __t_est = undefined; | |
| 18 __t_est_total = 0; | |
| 19 __t_est_squared_total = 0; | |
| 20 __t_count = 0; | |
| 21 } | |
| 22 __init_stats(); | |
| 23 | |
| 24 function __calc_results() { | |
| 25 var M = __t_est_total / __t_count; | |
| 26 var X = __t_est_squared_total / __t_count; | |
| 27 var V = X - M * M; | |
| 28 var S = Math.sqrt(V); | |
| 29 | |
| 30 var R = new Object(); | |
| 31 R.mean = 1000.0 / M; | |
| 32 R.sigma = R.mean - 1000.0 / (M + S); | |
| 33 return R; | |
| 34 } | |
| 35 | |
| 36 function __scroll_down() { | |
| 37 var y = window.scrollY; | |
| 38 window.scrollBy(0, __scroll_by); | |
| 39 if (window.scrollY == y) | |
| 40 __stop(); | |
| 41 } | |
| 42 | |
| 43 function __update_fps() { | |
| 44 var t_now = new Date().getTime(); | |
| 45 if (window.__t_last) { | |
| 46 var t_delta = t_now - __t_last; | |
| 47 if (window.__t_est) { | |
| 48 __t_est = (0.1 * __t_est) + (0.9 * t_delta); // low-pass filter | |
| 49 } else { | |
| 50 __t_est = t_delta; | |
| 51 } | |
| 52 var fps = 1000.0 / __t_est; | |
| 53 document.title = "FPS: " + (fps | 0); | |
|
nduca
2011/05/22 04:33:41
avoid updating the title at all? Its not strictly
| |
| 54 | |
| 55 __t_est_total += t_delta; | |
| 56 __t_est_squared_total += t_delta * t_delta; | |
|
nduca
2011/05/22 04:33:41
Would be curious what the t_est_squared is on nyti
| |
| 57 __t_count++; | |
| 58 } | |
| 59 __t_last = t_now; | |
| 60 } | |
| 61 | |
| 62 function __sched_update() { | |
| 63 webkitRequestAnimationFrame(function() { | |
|
nduca
2011/05/22 04:33:41
I think RAF passes in the frame begin time to the
| |
| 64 if (!__running) | |
| 65 return; | |
| 66 __update_fps(); | |
| 67 __scroll_down(); | |
| 68 __sched_update(); | |
| 69 }); | |
| 70 } | |
| 71 | |
| 72 function __start() { | |
|
nduca
2011/05/22 04:33:41
Maybe pass in scroll-by and some "am I done?" so t
| |
| 73 if (__running) | |
| 74 return; | |
| 75 __old_title = document.title; | |
| 76 __running = true; | |
| 77 __sched_update(); | |
| 78 } | |
| 79 | |
| 80 function __stop() { | |
| 81 __running = false; | |
| 82 document.title = __old_title; | |
| 83 } | |
| 84 | |
| 85 function __reset() { | |
| 86 __stop(); | |
| 87 document.body.scrollTop = 0; | |
| 88 __init_stats(); | |
| 89 } | |
| 90 | |
| 91 function __force_compositor() { | |
| 92 document.body.style.webkitTransform = "translateZ(0)"; | |
| 93 } | |
| OLD | NEW |