Created
October 12, 2012 12:54
-
-
Save anatoliychakkaev/3879071 to your computer and use it in GitHub Desktop.
Benchmark sample
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 score = 0; | |
var started = 0; | |
var http = require('http'); | |
require('./server'); | |
function request(params, callback) { | |
var req = new http.IncomingMessage; | |
req.headers = {host: params.host}; | |
req.url = params.path; | |
req.method = params.method || 'GET'; | |
req.connection = {}; | |
req.session = {userId: 1}; | |
var res = new http.ServerResponse({method: 'NOTHEAD'}); | |
res._headers = {}; | |
res.headers = {}; | |
res.setHeader = res.header = function (header, value) { | |
res.headers[header.toLowerCase()] = value; | |
}; | |
var render = res.render; | |
res.render = function () { | |
module.renderCallerWith = arguments; | |
res.end(); | |
}; | |
res.end = function () { | |
callback(); | |
}; | |
process.nextTick(function () { | |
app.handle(req, res); | |
}); | |
} | |
function benchmark() { | |
started += 1; | |
request({host: 'localhost', path: '/posts'}, finished); | |
} | |
var endTime; | |
function finished() { | |
score += 1; | |
if (score === 300) endTime = Date.now(); | |
} | |
var time = Date.now(); | |
while (started < 20000) { | |
benchmark(); | |
} | |
setTimeout(function () { | |
railway.ControllerBridge.poolSize(); | |
console.log(endTime - time); | |
process.exit(); | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment