Skip to content

Instantly share code, notes, and snippets.

@simonhearne
Last active September 11, 2015 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonhearne/659f4ab87a45dbe44a66 to your computer and use it in GitHub Desktop.
Save simonhearne/659f4ab87a45dbe44a66 to your computer and use it in GitHub Desktop.
(function(){
/* scrolls the page to the bottom */
function s2b() {
window.scrollTo(0,0); // reset screen position
count = 0;
sh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
h = Math.max(document.body.offsetHeight,document.body.scrollHeight) - sh;
chunk = 100; // scrollwheel distance?
if (h - chunk < 0) {
throw 'Page too short';
}
fA=[];
window.requestAnimationFrame(sl);
ll=false;
}
/* scrolls the page by one scroll-wheel turn and gets framerate */
function sl() {
if (!ll) {
ll = performance.now();
window.requestAnimationFrame(sl);
return;
}
window.scrollBy(0,chunk);
tl = performance.now();
fA.push(parseInt(1000/(tl-ll)));
ll = tl;
count += chunk;
if (count >= h) {
window.scrollTo(0,0);
cF(fA);
} else {
window.requestAnimationFrame(sl);
}
}
/* calculate stats */
function cF(v) {
// calculate median by sorting and select middle
v.sort( function(a,b) {return a - b;} );
var half = Math.floor(v.length/2);
if(v.length % 2)
var med = v[half];
else
var med = (v[half-1] + v[half]) / 2.0;
// min and max from sorted array
var mi = v[0];
var ma = v[v.length-1];
// mean by summing array and divide by total
var to = 0;
for (var i=0; i<v.length; i++) {
to+=v[i];
}
var mn = parseInt(to/v.length);
console.log("Median FPS: "+med);
console.log("Mean FPS: "+mn);
console.log("Min FPS: "+mi);
console.log("Max FPS: "+ma);
}
s2b();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment