Skip to content

Instantly share code, notes, and snippets.

@guileen
Created April 23, 2012 07:54
Show Gist options
  • Save guileen/2469423 to your computer and use it in GitHub Desktop.
Save guileen/2469423 to your computer and use it in GitHub Desktop.
node benchmark
var http = require('http')
http.createServer(function(req, res) {
res.end('hello world');
}).listen('/tmp/test.sock');
var http = require('http')
;
var startTime = Date.now();
var running = 0;
var max_running = 100;
var done = 0;
var total = 10000;
sendRequest();
function sendRequest() {
if(running > max_running) return;
var req = http.request({
socketPath: '/tmp/test.sock'
}, function(res) {
res.on('data', function(data) {
})
res.on('end', function() {
if(++done >= total) {
endProgram();
}
running --;
process.nextTick(sendRequest);
})
});
req.end();
if(running ++ < max_running) process.nextTick(sendRequest);
}
function endProgram() {
var ending = Date.now();
console.log(done * 1000 / (ending - startTime))
process.exit();
}
process.on('SIGINT', function(){
endProgram();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment