Skip to content

Instantly share code, notes, and snippets.

@strk
Created February 20, 2013 14:40
Show Gist options
  • Save strk/4995973 to your computer and use it in GitHub Desktop.
Save strk/4995973 to your computer and use it in GitHub Desktop.
Attempt to profile http request times
var start_time = Date.now();
http.get(url, function(res) {
res.body = '';
if ( res.statusCode != 200 ) {
res.on('data', function(chunk) {
// Save only first chunk, to reduce cost of the operation
if ( res.body.length == 0 ) res.body += chunk;
});
}
res.on('end', function() {
var now = Date.now();
var elapsed = now - start_time;
if ( elapsed > max_response_time ) max_response_time = elapsed;
if ( elapsed < min_response_time ) min_response_time = elapsed;
total_response_time += elapsed;
console.log("started at " + start_time + " ended at " + now + " took " + elapsed + " total: " + total_response_time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment