Last active
March 2, 2016 15:45
-
-
Save mattwiebe/059c8e5012e7438a8d39 to your computer and use it in GitHub Desktop.
Check performance up to a certain point in the page's load, multiple times
This file contains hidden or 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
/** | |
* To use: call the function at the point in the load you want to check performance for. | |
* The page will then reload for @var iterations times to provide multiple measures | |
*/ | |
function checkPerf() { | |
var mean; | |
var iterations = 10; | |
var times = localStorage.getItem( 'perf' ) ? JSON.parse( localStorage.getItem( 'perf' ) ) : []; | |
times.push( performance.now() ); | |
localStorage.setItem( 'perf', JSON.stringify( times ) ); | |
if ( times.length >= iterations ) { | |
mean = times.reduce( (p,c) => p + c, 0 ) / times.length; | |
console.log( Math.round( mean ) + ' ms is the mean over ' + times.length + ' iterations', times ); | |
alert( 'Performance checking done. Check the console for results.' ); | |
localStorage.removeItem( 'perf' ); | |
return; | |
} else { | |
location.reload(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment