Skip to content

Instantly share code, notes, and snippets.

@pathsny
Created May 22, 2012 16:21
Show Gist options
  • Select an option

  • Save pathsny/2770063 to your computer and use it in GitHub Desktop.

Select an option

Save pathsny/2770063 to your computer and use it in GitHub Desktop.
test of timed events on node
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();
}
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
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');
@gramki

gramki commented May 22, 2012

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment