Skip to content

Instantly share code, notes, and snippets.

@anatoliychakkaev
Created October 12, 2012 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatoliychakkaev/3879071 to your computer and use it in GitHub Desktop.
Save anatoliychakkaev/3879071 to your computer and use it in GitHub Desktop.
Benchmark sample
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