Skip to content

Instantly share code, notes, and snippets.

@csanz
Created March 22, 2011 00:14
Show Gist options
  • Select an option

  • Save csanz/880510 to your computer and use it in GitHub Desktop.

Select an option

Save csanz/880510 to your computer and use it in GitHub Desktop.
get the elapsed time from a server
/* usage
node get_elapsed_time.js -u localhost -p 8000 */
var start, elapsed, end, argv, http;
argv = require('optimist').argv;
http = require('http');
if (argv.u.length == 0) return console.log('need url');
start = new Date();
http.get({ host : argv.u , port: (argv.p) ? argv.p : 80}, function(res){
console.log('\nnget console util\n');
res.on('end', function(){
end = new Date();
elapsed = new Date();
elapsed.setTime(start.getTime() - end.getTime());
console.log(elapsed.getMilliseconds() + " ms elapsed");
});
});
var http = require('http');
var s = http.createServer(function(req, res){
res.writeHead(200, { 'content-type': 'text/plain' });
res.write("hello \n");
setTimeout(function(){
res.end("world\n");
}, 10000);
});
s.listen(8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment