Last active
August 24, 2016 20:53
-
-
Save rohanpadhye/5bb00fefd8f6b0eb5675fced1a7baca3 to your computer and use it in GitHub Desktop.
This file contains 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 express = require('express'); | |
var app = express(); | |
var router = express.Router(); | |
var M = 1000; // Size of path array | |
var N = 1000; // Size of middleware array | |
function fnNext(req, res, next) { | |
next(); | |
} | |
function fnDone(req, res, next) { | |
res.send('ok'); | |
} | |
// Set-up middleware array | |
var fnArr = []; | |
for (var i = 0; i < N; i++) { | |
fnArr.push(fnNext); | |
} | |
// Set-up path array | |
var path = []; | |
for (var i = 0; i < M; i++) { | |
path.push('/foo'+i); | |
} | |
// Benchmark | |
console.time('use-large'); | |
// Slow!! | |
app.use(path, [fnArr, fnDone]); | |
// or alternatively... | |
// router.use(path, [fnArr, fnDone]); | |
console.timeEnd('use-large'); | |
process.exit(0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment