Created
May 22, 2012 16:21
-
-
Save pathsny/2770063 to your computer and use it in GitHub Desktop.
test of timed events on node
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 client = http.createClient(1337, 'localhost'); // to access this url i need to put basic auth. | |
| for (var j=0; j<=100000; j++) { | |
| var request = client.request('GET', '/', | |
| {'host': 'www.example.com'}); | |
| request.end(); | |
| } |
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
| Tue, 22 May 2012 16:17:37 GMT | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| timed event after 10030 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| timed event after 11561 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| timed event after 10659 |
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 cpu_func = function() { | |
| var count = 0; | |
| for (var i=0; i<=100000000; i++) { | |
| count += Math.random(); | |
| } | |
| return count; | |
| } | |
| var foo = undefined | |
| var now; | |
| var display = function() { | |
| console.log('timed event after ' + (new Date() - now)) | |
| now = new Date(); | |
| setTimeout(display, 10000) | |
| } | |
| var http = require('http'); | |
| var count =0; | |
| http.createServer(function (req, res) { | |
| if (!foo) { | |
| foo = true; | |
| now = new Date(); | |
| console.log(now); | |
| setTimeout(display, 10000); | |
| } | |
| count ++; | |
| res.writeHead(200, {'Content-Type': 'text/plain'}); | |
| res.end('Hello World\n ' + cpu_func()); | |
| console.log(count); | |
| }).listen(1337, '127.0.0.1'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/2771186