Created
October 14, 2016 19:20
-
-
Save vrinek/99cfdd8d8d48837fd2fd7db6602f2fd3 to your computer and use it in GitHub Desktop.
This file contains 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
var http = require('http'); | |
var countdown = 10; | |
function makeRequest(iteration) { | |
var t = Date.now(); | |
http.request({ | |
host: 'www.google.com', | |
path: '/' | |
}, function(response){ | |
var str = ''; | |
response.on('error', function(err){ | |
console.error(err); | |
}); | |
response.on('data', function(chunk){ | |
str += chunk; | |
}); | |
response.on('end', function(){ | |
console.log(response.statusCode, str.length, Date.now() - t); | |
}); | |
}).end(function(){ | |
iteration++; | |
if(iteration <= countdown) { | |
setTimeout(function(){ | |
makeRequest(iteration); | |
}, 500); | |
} | |
}); | |
} | |
makeRequest(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment