-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
086443a
commit 9ea0db2
Showing
1 changed file
with
111 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const httpNext = require('./index') | ||
const httpPrevious = require('0http') | ||
|
||
function getReqObject (url) { | ||
const req = {} | ||
req.method = 'GET' | ||
req.url = url | ||
|
||
return req | ||
} | ||
|
||
function getResObject () { | ||
const res = {} | ||
res.statusCode = null | ||
res.setHeader = () => {} | ||
res.writeHead = () => {} | ||
res.end = () => {} | ||
return res | ||
} | ||
|
||
function setupRouter (router) { | ||
router.use((req, res, next) => { | ||
return next() | ||
}) | ||
|
||
router.get('/', (req, res) => { | ||
return res.end('OK') | ||
}) | ||
router.get('/:id', (req, res) => { | ||
return res.end(req.params.id) | ||
}) | ||
router.get('/:id/error', () => { | ||
throw new Error('Error') | ||
}) | ||
} | ||
|
||
const { router } = httpNext({ | ||
cacheSize: 0, | ||
id: '/' | ||
}) | ||
setupRouter(router) | ||
|
||
const { router: routerPrevious } = httpPrevious({ | ||
cacheSize: 0 | ||
}) | ||
setupRouter(routerPrevious) | ||
|
||
import('mitata/src/cli.mjs').then(({ run, bench, group, baseline }) => { | ||
group('Next Router', () => { | ||
baseline('Base URL', () => { | ||
const req = getReqObject('/') | ||
const res = getResObject() | ||
|
||
router.lookup(req, res) | ||
}) | ||
bench('Parameter URL', () => { | ||
const req = getReqObject('/0') | ||
const res = getResObject() | ||
|
||
router.lookup(req, res) | ||
}) | ||
bench('Not Found URL', () => { | ||
const req = getReqObject('/0/404') | ||
const res = getResObject() | ||
|
||
router.lookup(req, res) | ||
}) | ||
bench('Error URL', () => { | ||
const req = getReqObject('/0/error') | ||
const res = getResObject() | ||
|
||
router.lookup(req, res) | ||
}) | ||
}) | ||
|
||
group('Previous Router', () => { | ||
baseline('Base URL', () => { | ||
const req = getReqObject('/') | ||
const res = getResObject() | ||
|
||
routerPrevious.lookup(req, res) | ||
}) | ||
bench('Parameter URL', () => { | ||
const req = getReqObject('/0') | ||
const res = getResObject() | ||
|
||
routerPrevious.lookup(req, res) | ||
}) | ||
bench('Not Found URL', () => { | ||
const req = getReqObject('/0/404') | ||
const res = getResObject() | ||
|
||
routerPrevious.lookup(req, res) | ||
}) | ||
bench('Error URL', () => { | ||
const req = getReqObject('/0/error') | ||
const res = getResObject() | ||
|
||
routerPrevious.lookup(req, res) | ||
}) | ||
}) | ||
|
||
run({ | ||
silent: false, | ||
avg: true, | ||
json: false, | ||
colors: true, | ||
min_max: false, | ||
percentiles: false | ||
}) | ||
}) |