Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
added express / connect-router benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Condon committed Jan 23, 2012
1 parent 77bc8d6 commit a729221
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 6 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ router.on('-perm /**', function(req, res, next) {
});


//goes through perm middleware
//goes through permissions middleware
router.on('-perm=SUPER invite/user', function(req, res, next) {

res.send('You have invited a user!');
Expand Down
13 changes: 10 additions & 3 deletions examples/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ connectRouter = require('../');




app.use(connectRouter.create(function(router) {
app.use(connectRouter(function(router) {

router.on('-method=GET hello/world', function(req, res, next) {

res.send('hello');
});

return;

router.on('parseBody', express.bodyParser());
router.on('parseCookies', express.cookieParser());

Expand Down Expand Up @@ -39,4 +45,5 @@ app.use(connectRouter.create(function(router) {



app.listen(8080);

app.listen(8090);
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ module.exports = function() {

var _next, current = chain.shift();

if(chain.length) {
req.hasNext = !!chain.length;

if(req.hasNext) {

_next = function() {

Expand All @@ -65,11 +67,13 @@ module.exports = function() {
}

} else {


//last next is 404
_next = next;

}


req.params = current.params;

current.value(req, res, _next, chain);
Expand Down
15 changes: 15 additions & 0 deletions test/benchmark-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@



module.exports = function() {
var chars = 'abcdefghijklmnopqrstuvwxyz0122345689',
routes = [];

for(var i = 0; i < chars.length; i++) {
routes.push(chars.substr(0,i).split('').join('/'));
}

return routes;
}


70 changes: 70 additions & 0 deletions test/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var express = require('express'),
app1 = express.createServer(),
app2 = express.createServer(),
connectRouter = require('../'),
routes = require('./benchmark-routes')();







app1.use(connectRouter(function(router) {

for(var i = routes.length; i--;) {

var mw = i != 0 ? routes.slice(0, i-1) : [];

mw.push(routes[i]);


router.on('-method=GET ' + mw.join(' -> '), function(req, res, next) {

if(req.hasNext) {
next();
return;
}

res.send('DONE');
});
}


}));


var thru = {};

for(var i = 0; i < routes.length; i++) {

var fns = [], middleware = i != 0 ? routes.slice(0, i-1) : [], croute;

var uri = routes[i];

middleware.forEach(function(mw) {
fns.push(thru[mw]);
});

thru[uri] = function(req, res, next) {

next();

}

fns.push(thru[uri]);

app2.get('/'+uri, fns, function(req, res) {
res.send('DONE')
});
}





//connect-router
app1.listen(8090);


app2.listen(8091);

0 comments on commit a729221

Please sign in to comment.