Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Silly benchmarks
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
@kud
kud commented Jun 10, 2012

Results:

  • Casperjs:

http://google.com/ loaded in 1727ms
http://yahoo.com/ loaded in 9154ms
http://bing.com/ loaded in 1204ms

  • Phantomjs

loaded google in 2402ms
loaded yahoo in 8139ms
loaded bing in 667ms

@n1k0
Owner
n1k0 commented Jun 10, 2012

Mouais, faudrait en jouer au moins 1000 pour avoir des moyennes parlantes ;)

Merci en tout cas !

@n1k0
Owner
n1k0 commented Jun 10, 2012

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)

@kud
kud commented Jun 10, 2012
@kud
kud commented Jun 10, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment