Created
March 22, 2011 00:14
-
-
Save csanz/880510 to your computer and use it in GitHub Desktop.
get the elapsed time from a server
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
| /* 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"); | |
| }); | |
| }); |
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
| 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