Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added express / connect-router benchmark

  • Loading branch information...
commit a7292216f0b5a27ace60b94c8881146caddfef9f 1 parent 77bc8d6
@crcn authored
View
BIN  .DS_Store
Binary file not shown
View
2  README.md
@@ -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!');
View
13 examples/auth.js
@@ -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());
@@ -39,4 +45,5 @@ app.use(connectRouter.create(function(router) {
-app.listen(8080);
+
+app.listen(8090);
View
8 lib/index.js
@@ -55,7 +55,9 @@ module.exports = function() {
var _next, current = chain.shift();
- if(chain.length) {
+ req.hasNext = !!chain.length;
+
+ if(req.hasNext) {
_next = function() {
@@ -65,11 +67,13 @@ module.exports = function() {
}
} else {
-
+
+ //last next is 404
_next = next;
}
+
req.params = current.params;
current.value(req, res, _next, chain);
View
15 test/benchmark-routes.js
@@ -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;
+}
+
+
View
70 test/benchmark.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.