Create a gist now

Instantly share code, notes, and snippets.

A simple snippet you can add to your bookmark bar (insert javascript: in front) to measure rendering performance of a state of a webpage
javascript:(function (window,$,runs) { var t = new Date(), i = 1, timetaken,offset = $(window).scrollTop(); $(window).bind('scroll.scrolltest',function () { if (i >= runs) { timetaken = (new Date) - t; console.log('Time taken for '+runs+' scrolls: ',timetaken,' - time per scroll: ', timetaken/runs); $(window).unbind('scroll.scrolltest'); return; } i++; doScroll(); }); function mod (x,y) { return Math.round((x/y - Math.floor(x/y)) *2); } function doScroll () { setTimeout(function(){ $(window).scrollTop(offset + mod(i,2)*100); },0); } doScroll(); })(window,jQuery,500);
// Note: this requires that the jQuery object ($) is present on the page
// The stats are displayed in the console
(function (window,$,runs) {
var t = new Date(), i = 1, timetaken,offset = $(window).scrollTop();
$(window).bind('scroll.scrolltest',function () {
if (i >= runs) {
timetaken = (new Date) - t;
console.log('Time taken for '+runs+' scrolls: ',timetaken,' - time per scroll: ', timetaken/runs);
$(window).unbind('scroll.scrolltest');
return;
}
i++;
doScroll();
});
// was having problems linking to the bookmarklet, due to the modulus operator, so I need to hack my
// own w/o using an actual modulus
// also making sure the number's round, in case some browsers have retarded floating point calcs
function mod (x,y) {
return Math.round((x/y - Math.floor(x/y)) *2);
}
function doScroll () {
// I had to do this really ugly hack to make the scrolling always get triggered - not sure why
// posssible reasons might be that the scroll event doesn't get triggered on every scroll and/or
// there's some sort of ratelimit done by the browser to improve scrolling performance on
// Javascript
setTimeout(function(){
$(window).scrollTop(offset + mod(i,2)*100);
},0);
}
doScroll();
})(window,jQuery,500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment