Created
December 21, 2016 06:49
-
-
Save tejom/f4b520ab003a895ec0bf9cd2ee08e201 to your computer and use it in GitHub Desktop.
nodejs http request measurments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
require('net') | |
var options = { | |
host: 'www.google.com', | |
path: '/' | |
}; | |
endtimer = process.hrtime() | |
for( x=0;x<20;x++){ | |
let l=x | |
var req = http.request(options, function cb(res){ | |
console.log("cb:" + l) | |
let start = process.hrtime(); | |
res.setEncoding('utf8'); | |
res.on('data',(chunk)=>{ | |
diff = process.hrtime(start); | |
console.log(l +" - data" + ( (diff[1] * 1e-9) + diff[0] )) | |
}) | |
res.on('socket',(data) =>{ | |
console.log("socket") | |
}) | |
res.on("end",(end)=>{ | |
diff = process.hrtime(start); | |
console.log(l + " - end:" + ( (diff[1] * 1e-9) + diff[0] )) | |
endt = process.hrtime(endtimer) | |
console.log(l + " - totalend:" + ( (endt[1] * 1e-9) + endt[0] )) | |
}) | |
}); | |
req.end() | |
} | |
// var request = require('request'); | |
// for( x=0;x<1;x++){ | |
// let l=x | |
// let start2 = process.hrtime(); | |
// request('http://www.google.com', function (error, response, body) { | |
// if (!error && response.statusCode == 200) { | |
// //console.log(body) // Show the HTML for the Google homepage. | |
// diff = process.hrtime(start2); | |
// console.log("req " + l +"- end:" + ( (diff[1] * 1e-9) + diff[0] )) | |
// } | |
// }) | |
// } | |
total = 0 | |
// var rp = require('request-promise'); | |
// for( x=0;x<20;x++){ | |
// let l=x | |
// let start3 = process.hrtime(); | |
// rp('http://www.google.com') | |
// .then(function (htmlString) { | |
// //console.log(htmlString) | |
// diff = process.hrtime(start3); | |
// console.log("rp "+l +"- end:" + ( (diff[1] * 1e-9) + diff[0] )) | |
// total += (diff[1] * 1e-9) + diff[0] | |
// console.log("total:" + total) | |
// }) | |
// .catch(function (err) { | |
// // Crawling failed... | |
// console.log(err) | |
// }); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment