Tôi đã poking xung quanh recenlty khám phá nodejs và phantomjs và đã viết một mã nhỏ để đo thời gian tải trang. Tôi đã thấy rằng thời gian tải trang khác nhau giữa mã phantomjs được bao bọc trong nútjs so với mã phantomjs thuần túy. Dưới đây là các mã: phantomjs và nodejs để so sánh:Nodejs + phantomjs so với phantomjs tinh khiết - thời gian tải trang
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 + '');
});
Hiện thường là 4 lần lâu hơn khi thử nghiệm một trang web thông qua phantomjs. Bất kỳ ý tưởng?
Dump lưu lượng mạng từ PhantomJS (cho cả hai trường hợp) và so sánh chúng. Xem https://github.com/ariya/phantomjs/wiki/Network-Monitoring. –
Bạn có thể làm rõ, lệnh gọi phantomjs trực tiếp dài hơn 4 lần so với phantomjs & nodejs? –
http://phantomjs.org/network-monitoring.html (Liên kết Mới) –