Skip to content

Commit 825d626

Browse files
committed
Refactor benchmark tests and update dependencies for improved performance
1 parent fda5ccd commit 825d626

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

bench.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,60 +44,44 @@ const { router: routerPrevious } = httpPrevious({
4444
cacheSize: 0
4545
})
4646
setupRouter(routerPrevious)
47-
48-
import('mitata/src/cli.mjs').then(({ run, bench, group, baseline }) => {
49-
group('Next Router', () => {
50-
baseline('Base URL', () => {
51-
const req = getReqObject('/')
47+
import('mitata').then(({ run, bench, group }) => {
48+
group('Routers', () => {
49+
bench('Next Router Parameter URL', () => {
50+
const req = getReqObject('/0')
5251
const res = getResObject()
5352

5453
router.lookup(req, res)
55-
})
56-
bench('Parameter URL', () => {
54+
}).gc('inner')
55+
bench('Previous Router Parameter URL', () => {
5756
const req = getReqObject('/0')
5857
const res = getResObject()
5958

60-
router.lookup(req, res)
61-
})
62-
bench('Not Found URL', () => {
59+
routerPrevious.lookup(req, res)
60+
}).gc('inner')
61+
bench('Next Router Not Found URL', () => {
6362
const req = getReqObject('/0/404')
6463
const res = getResObject()
6564

6665
router.lookup(req, res)
67-
})
68-
bench('Error URL', () => {
69-
const req = getReqObject('/0/error')
70-
const res = getResObject()
71-
72-
router.lookup(req, res)
73-
})
74-
})
75-
76-
group('Previous Router', () => {
77-
baseline('Base URL', () => {
78-
const req = getReqObject('/')
79-
const res = getResObject()
80-
81-
routerPrevious.lookup(req, res)
82-
})
83-
bench('Parameter URL', () => {
84-
const req = getReqObject('/0')
66+
}).gc('inner')
67+
bench('Previous Router Not Found URL', () => {
68+
const req = getReqObject('/0/404')
8569
const res = getResObject()
8670

8771
routerPrevious.lookup(req, res)
88-
})
89-
bench('Not Found URL', () => {
90-
const req = getReqObject('/0/404')
72+
}).gc('inner')
73+
bench('Next Router Error URL', () => {
74+
const req = getReqObject('/0/error')
9175
const res = getResObject()
9276

93-
routerPrevious.lookup(req, res)
94-
})
95-
bench('Error URL', () => {
77+
router.lookup(req, res)
78+
}).gc('inner')
79+
bench('Previous Router Error URL', () => {
9680
const req = getReqObject('/0/error')
9781
const res = getResObject()
9882

9983
routerPrevious.lookup(req, res)
100-
})
84+
}).gc('inner')
10185
})
10286

10387
run({

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"format": "npx standard --fix",
8-
"test": "cross-env PORT=3000 NODE_ENV=testing npx nyc --check-coverage --lines 85 node ./node_modules/mocha/bin/mocha tests/*.test.js"
8+
"test": "cross-env PORT=3000 NODE_ENV=testing npx nyc --check-coverage --lines 85 node ./node_modules/mocha/bin/mocha tests/*.test.js",
9+
"bench": "node --expose-gc bench.js"
910
},
1011
"repository": {
1112
"type": "git",
@@ -27,12 +28,12 @@
2728
},
2829
"homepage": "https://github.com/BackendStack21/0http#readme",
2930
"devDependencies": {
30-
"0http": "^3.5.2",
31+
"0http": "^4.0.0",
3132
"@types/node": "^22.10.5",
3233
"body-parser": "^1.20.1",
3334
"chai": "^4.3.7",
3435
"cross-env": "^7.0.3",
35-
"mitata": "^0.1.11",
36+
"mitata": "^1.0.30",
3637
"mocha": "^11.0.1",
3738
"nyc": "^17.1.0",
3839
"supertest": "^7.0.0"

0 commit comments

Comments
 (0)