Created
December 11, 2011 08:28
-
-
Save arnorhs/1459352 to your computer and use it in GitHub Desktop.
A simple snippet you can add to your bookmark bar (insert javascript: in front) to measure rendering performance of a state of a webpage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
Omg, I was left squinting watching the screen flicker xD
Still, nice snippet!