Szukałem recenlty badając nodejs i phantomjs i napisałem mały kod, by zmierzyć czas wczytywania strony. Zauważyłem, że czas ładowania strony różni się między kodem phantomjs owiniętym w nodejs a czystym kodem phantomjs. Poniżej znajduje się kod: phantomjs i nodejs dla porównania:Nodejs + phantomjs vs. czysty phantomjs - czas wczytywania strony
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 + '');
});
Czas jest zwykle 4 razy dłużej podczas testowania witryny poprzez phantomjs. Jakieś pomysły?
Zrzuć ruch sieciowy z PhantomJS (w obu przypadkach) i porównaj. Zobacz https://github.com/ariya/phantomjs/wiki/Network-Monitoring. –
Proszę wyjaśnić, bezpośrednie wywołanie phantomjs jest 4 razy dłuższe niż phantomjs i nodejs? –
http://phantomjs.org/network-monitoring.html (Nowe łącze) –