6
我正在探索recenlty探索nodejs和phantomjs,並寫了一個小代碼來測量頁面加載時間。我發現頁面加載時間在包裝在nodejs中的phantomjs代碼與純幻影代碼相比有所不同。下面是代碼:phantomjs和爲的NodeJS比較:Nodejs + phantomjs與純幻影 - 頁面加載時間
的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 + '');
});
的時間通常是4倍的時間經由phantomjs測試網站時。有任何想法嗎?
轉儲來自PhantomJS的網絡流量(兩種情況)並進行比較。請參閱https://github.com/ariya/phantomjs/wiki/Network-Monitoring。 –
請您澄清一下,直接phantomjs調用比phantomjs&nodejs長4倍? –
http://phantomjs.org/network-monitoring.html(新鏈接) –