Last active
September 4, 2015 14:23
-
-
Save desigens/7d5d7fc07a826b088b25 to your computer and use it in GitHub Desktop.
Script to get page initialisation average time.
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
/** | |
* PhantomJS script to get page initialisation average time. | |
* Using: ```$ phantom pagespeed.js http://mypage.com 10``` | |
**/ | |
var _ = require('underscore'); | |
var webpage = require('webpage'); | |
var url = process.argv[2] || 'http://google.com'; | |
var times = 5 || process.argv[3]; | |
var i = 0; | |
var results = []; | |
function test() { | |
phantom.clearCookies(); | |
var page = webpage.create(); | |
var t = Date.now(); | |
page.open(url, function(status) { | |
if(status === "success") { | |
results.push(Date.now() - t); | |
} | |
if (++i < times) { | |
a(); | |
} else { | |
// Result | |
console.log('average', _.reduce(results, | |
function(memo, num) {return memo + num;}, 0) / (results.length === 0 ? 1 : results.length), | |
'(' + results.length + ')'); | |
phantom.exit(); | |
} | |
}); | |
} | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment