Stavo curiosando per esplorare recenlty nodejs e phantomjs e ho scritto un piccolo codice per misurare il tempo di caricamento della pagina. Ho trovato che i tempi di caricamento della pagina differiscono tra il codice phantomjs racchiuso in nodejs rispetto al puro codice phantomjs. Di seguito è riportato il codice: phantomjs e nodejs per il confronto:Nodejs + phantomjs vs pure phantomjs - tempo di caricamento della pagina
Nodejs:
var http = require('http'),
phantom = require('phantom');
url = require("url");
http.createServer(function (request, response) {
var start = Date.now();
request.on('end', function() {
phantom.create(function(ph) {
ph.createPage(function(page) {
var _get = url.parse(request.url, true).query;
page.open(_get[url], function(status) {
if (status == 'success') {
var time = Date.now() - start;
console.log(time);
}
});
});
});
});
}).listen(80,'');
Phantomjs:
var page = require('webpage').create();
var system = require('system');
var address = system.args[1];
var time = 0;
var start = Date.now();
page.open(address, function (status) {
time = Date.now() - start;
console.log(time + '');
});
il tempo è di solito 4 volte di più quando si verifica un sito tramite phantomjs. Qualche idea?
Scaricare il traffico di rete da PhantomJS (per entrambi i casi) e confrontarli. Vedi https://github.com/ariya/phantomjs/wiki/Network-Monitoring. –
Si prega di chiarire, la chiamata phantomjs diretta è 4 volte più lunga di phantomjs e nodejs? –
http://phantomjs.org/network-monitoring.html (Nuovo collegamento) –