-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbench.js
95 lines (81 loc) · 2.03 KB
/
bench.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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').then(({ run, bench, group }) => {
group('Routers', () => {
bench('Next Router Parameter URL', () => {
const req = getReqObject('/0')
const res = getResObject()
router.lookup(req, res)
}).gc('inner')
bench('Previous Router Parameter URL', () => {
const req = getReqObject('/0')
const res = getResObject()
routerPrevious.lookup(req, res)
}).gc('inner')
bench('Next Router Not Found URL', () => {
const req = getReqObject('/0/404')
const res = getResObject()
router.lookup(req, res)
}).gc('inner')
bench('Previous Router Not Found URL', () => {
const req = getReqObject('/0/404')
const res = getResObject()
routerPrevious.lookup(req, res)
}).gc('inner')
bench('Next Router Error URL', () => {
const req = getReqObject('/0/error')
const res = getResObject()
router.lookup(req, res)
}).gc('inner')
bench('Previous Router Error URL', () => {
const req = getReqObject('/0/error')
const res = getResObject()
routerPrevious.lookup(req, res)
}).gc('inner')
})
run({
silent: false,
avg: true,
json: false,
colors: true,
min_max: false,
percentiles: false
})
})