2012-12-14 62 views
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測試網站時。有任何想法嗎?

+1

轉儲來自PhantomJS的網絡流量(兩種情況)並進行比較。請參閱https://github.com/ariya/phantomjs/wiki/Network-Monitoring。 –

+1

請您澄清一下,直接phantomjs調用比phantomjs&nodejs長4倍? –

+0

http://phantomjs.org/network-monitoring.html(新鏈接) –

回答

0

PhantomJS不支持輸出數據,它只打開一個網頁。 phantomjs-node以下列方式連接它們 - 它創建一個ExpressJS實例,並使用兩個以上的庫通過其socket.io plus傳輸數據。和數據雲:

好康> Phantom.js>dnode + node-browserify> Express.js> Socket.io> Node.js的

我的速度和性能,現在閱讀node-webkit同樣的問題,這是本機WebKit沒有支持Node.js模塊的柺杖。