Created
April 23, 2012 07:54
-
-
Save guileen/2469423 to your computer and use it in GitHub Desktop.
node benchmark
This file contains 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') | |
http.createServer(function(req, res) { | |
res.end('hello world'); | |
}).listen('/tmp/test.sock'); |
This file contains 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 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