public
Created

Benchmark sample

  • Download Gist
benchmark.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.