-
-
Save n1k0/2906650 to your computer and use it in GitHub Desktop.
var casper = require("casper").create(); | |
var start = new Date().getTime(); | |
var links = [ | |
"http://google.com/", | |
"http://yahoo.com/", | |
"http://bing.com/" | |
]; | |
casper.start(); | |
casper.each(links, function(self, link) { | |
this.thenOpen(link, function() { | |
var now = new Date().getTime(); | |
this.echo(link + ' loaded in ' + (now - start) + 'ms'); | |
start = now; | |
}); | |
}); | |
casper.run(); |
http://google.com/ loaded in 3643ms | |
http://yahoo.com/ loaded in 12398ms | |
http://bing.com/ loaded in 1005ms |
var links = [ | |
"http://google.com/", | |
"http://yahoo.com/", | |
"http://bing.com/" | |
]; | |
var start = new Date().getTime(); | |
var page = require('webpage').create(); | |
page.open("http://google.com/", function() { | |
var now = new Date().getTime(); | |
console.log('loaded google in ' + (now - start) + 'ms'); | |
start = now; | |
page.open("http://yahoo.com/", function() { | |
var now = new Date().getTime(); | |
console.log('loaded yahoo in ' + (now - start) + 'ms'); | |
start = now; | |
page.open("http://bing.com/", function() { | |
var now = new Date().getTime(); | |
console.log('loaded bing in ' + (now - start) + 'ms'); | |
start = now; | |
phantom.exit(); | |
}); | |
}); | |
}); |
loaded google in 4568ms | |
loaded yahoo in 10839ms | |
loaded bing in 1849ms |
Mouais, faudrait en jouer au moins 1000 pour avoir des moyennes parlantes ;)
Merci en tout cas !
En tout cas, tout ceci est très lié à la qualité de la connectivité… Sinon essaye de désactiver le chargement des plugins et des images:
var casper = require('casper').create({
pageSettings: {
loadImages: false,
loadPlugins: false
}
});
Le chargement des images peut pas mal altérer le temps de chargement des pages… Yu peux aussi utiliser le cache du navigateur en passant l'option --disk-cache=yes
:
$ casperjs --disk-cache=yes casper_speed.js
(l'astuce fonctionne aussi avec phantomjs)
casperjs ❯ casperjs --disk-cache=yes casper_speed.js
http://google.com/ loaded in 1196ms
http://yahoo.com/ loaded in 3492ms
http://bing.com/ loaded in 1362ms
casperjs ❯ casperjs --disk-cache=yes casper_speed.js
http://google.com/ loaded in 659ms
http://yahoo.com/ loaded in 2451ms
http://bing.com/ loaded in 911ms
casperjs ❯ casperjs --disk-cache=yes casper_speed.js
http://google.com/ loaded in 656ms
http://yahoo.com/ loaded in 2489ms
http://bing.com/ loaded in 751ms
casperjs ❯ casperjs --disk-cache=yes casper_speed.js
http://google.com/ loaded in 656ms
http://yahoo.com/ loaded in 2571ms
http://bing.com/ loaded in 730ms
Results:
http://google.com/ loaded in 1727ms
http://yahoo.com/ loaded in 9154ms
http://bing.com/ loaded in 1204ms
loaded google in 2402ms
loaded yahoo in 8139ms
loaded bing in 667ms