Created
September 8, 2014 11:29
-
-
Save cybermaxs/cba5b498bb50cda020cb to your computer and use it in GitHub Desktop.
Compares page load time between HTML5 Navigation timings and basic computation using Date.now() (examples/loadspeed.js). Requires PhantomJS 2.0
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
var page = require('webpage').create(), | |
system = require('system'), | |
t, address; | |
if (system.args.length === 1) { | |
console.log('Usage: loadspeedv2.js <some URL>'); | |
phantom.exit(1); | |
} else { | |
t = Date.now(); | |
address = system.args[1]; | |
page.open(address, function (status) { | |
if (status !== 'success') { | |
console.log('FAIL to load the address'); | |
} else { | |
t = Date.now() - t; | |
console.log('Loading time (PhantomJS) ' + t + ' msec'); | |
setTimeout(function() { | |
//wait a few ms ... | |
var timings = page.evaluate(function () { | |
return window.performance.timing; | |
}); | |
console.log('Loading time (Navigation Timing) ' + (timings.loadEventEnd-timings.navigationStart) + ' msec'); | |
phantom.exit(); | |
}, 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
//sample output | |
C:\phantomjs>phantomjs.exe loadspeedv2.js http://www.amazon.com/ | |
Loading time (PhantomJS) 1862 msec | |
Loading time (Navigation Timing) 1861 msec | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment