Skip to content

Commit cf73959

Browse files
committed
Merge branch 'master' of https://github.com/tinyhttp/milliparsec into feature-basic-form-data/multipart-support
2 parents c1250a8 + 91d1b8f commit cf73959

18 files changed

+1816
-876
lines changed

Diff for: .eslintrc

-7
This file was deleted.

Diff for: .github/workflows/main.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ jobs:
2222
# Steps represent a sequence of tasks that will be executed as part of the job
2323
steps:
2424
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25-
- uses: actions/checkout@v2
26-
- uses: actions/setup-node@v2-beta
25+
- uses: actions/checkout@v4
26+
- name: Enable corepack
27+
run: corepack enable pnpm
28+
- uses: actions/setup-node@v4
2729
with:
28-
node-version: '16.3.0'
29-
- name: install pnpm
30-
uses: pnpm/[email protected]
31-
with:
32-
version: 6.8.0
30+
node-version: 18
31+
cache: 'pnpm'
3332
- run: pnpm install
3433
- run: pnpm test:coverage
3534
- run: pnpm test:report

Diff for: .prettierrc.json

-8
This file was deleted.

Diff for: .vscode/settings.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"biome.enabled": true,
3+
"editor.defaultFormatter": "biomejs.biome",
4+
"prettier.enable": false,
5+
"eslint.enable": false,
6+
"editor.codeActionsOnSave": {
7+
"source.fixAll": "always"
8+
},
9+
"typescript.tsdk": "node_modules/typescript/lib",
10+
"[typescript]": {
11+
"editor.defaultFormatter": "biomejs.biome"
12+
},
13+
"[javascript]": {
14+
"editor.defaultFormatter": "biomejs.biome"
15+
}
16+
}

Diff for: README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ Check out [deno-libs/parsec](https://github.com/deno-libs/parsec) for Deno port.
1717

1818
- ⏩ built with `async` / `await`
1919
- 🛠 JSON / raw / urlencoded data support
20-
- 📦 tiny package size (728B)
20+
- 📦 tiny package size (7.39KB)
2121
- 🔥 no dependencies
22-
-[tinyhttp](https://github.com/talentlessguy/tinyhttp) and Express support
22+
-[tinyhttp](https://github.com/tinyhttp/tinyhttp) and Express support
23+
- ⚡ 30% faster than body-parser
2324

2425
## Install
2526

@@ -108,6 +109,6 @@ The parsec is a unit of length used to measure large distances to astronomical o
108109
[npm-url]: https://www.npmjs.com/package/milliparsec
109110
[dl-badge-url]: https://img.shields.io/npm/dt/milliparsec?style=for-the-badge&color=25608B
110111
[github-actions]: https://github.com/talentlessguy/milliparsec/actions
111-
[gh-actions-img]: https://img.shields.io/github/workflow/status/talentlessguy/milliparsec/CI?style=for-the-badge&color=25608B&label=&logo=github
112+
[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/milliparsec/main.yml?branch=master&style=for-the-badge&color=25608B&label=&logo=github
112113
[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/milliparsec?style=for-the-badge&color=25608B
113114
[cov-url]: https://coveralls.io/github/tinyhttp/milliparsec

Diff for: bench/body-parser.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @ts-check
2+
3+
import bodyParser from 'body-parser'
4+
import { createServer } from 'node:http'
5+
6+
const mw = bodyParser.json()
7+
8+
const server = createServer((req, res) => {
9+
mw(req, res, () => {
10+
// @ts-expect-error added by body parser
11+
res.end(JSON.stringify(req.body))
12+
})
13+
})
14+
15+
server.listen(3002)

Diff for: bench/index.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Benchmark
2+
3+
Below is a comparison of body-parser and milliparsec in terms of parsing a request with JSON payload.
4+
5+
### Environment
6+
7+
- Node.js 22.3.0
8+
- System: Linux 6.9.7
9+
- Machine: Asus ROG Zephyrus G16
10+
11+
### Benchmark command:
12+
13+
```sh
14+
autocannon -b '{"a":1}' -H "Content-Type=application/json" localhost:3002 # or 3003
15+
```
16+
17+
### Results
18+
19+
body-parser result:
20+
21+
```
22+
┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐
23+
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
24+
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤
25+
│ Latency │ 0 ms │ 0 ms │ 0 ms │ 0 ms │ 0.01 ms │ 0.79 ms │ 251 ms │
26+
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘
27+
┌───────────┬─────────┬─────────┬─────────┬─────────┬───────────┬──────────┬─────────┐
28+
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
29+
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤
30+
│ Req/Sec │ 31,231 │ 31,231 │ 42,815 │ 43,935 │ 41,823.28 │ 3,470.88 │ 31,224 │
31+
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤
32+
│ Bytes/Sec │ 4.03 MB │ 4.03 MB │ 5.52 MB │ 5.67 MB │ 5.39 MB │ 448 kB │ 4.03 MB │
33+
└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴─────────┘
34+
35+
Req/Bytes counts sampled once per second.
36+
# of samples: 11
37+
38+
460k requests in 11.02s, 59.3 MB read
39+
```
40+
41+
milliparsec result:
42+
43+
```
44+
┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐
45+
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
46+
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤
47+
│ Latency │ 0 ms │ 0 ms │ 0 ms │ 0 ms │ 0.01 ms │ 0.65 ms │ 254 ms │
48+
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘
49+
┌───────────┬─────────┬─────────┬─────────┬─────────┬───────────┬──────────┬────────┐
50+
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
51+
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼────────┤
52+
│ Req/Sec │ 52,511 │ 52,511 │ 63,007 │ 67,455 │ 63,397.82 │ 4,255.42 │ 52,480 │
53+
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼────────┤
54+
│ Bytes/Sec │ 6.41 MB │ 6.41 MB │ 7.69 MB │ 8.23 MB │ 7.74 MB │ 519 kB │ 6.4 MB │
55+
└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴────────┘
56+
57+
Req/Bytes counts sampled once per second.
58+
# of samples: 11
59+
60+
697k requests in 11.02s, 85.1 MB rea
61+
```
62+
63+
## Verdict
64+
65+
milliparsec, on average, is ~34% faster.

Diff for: bench/milliparsec.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @ts-check
2+
3+
import { createServer } from 'node:http'
4+
import * as bodyParser from '../dist/index.js'
5+
6+
const mw = bodyParser.json()
7+
8+
const server = createServer((req, res) => {
9+
mw(req, res, () => {
10+
// @ts-expect-error added by body parser
11+
res.end(JSON.stringify(req.body))
12+
})
13+
})
14+
15+
server.listen(3003)

Diff for: bench/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "bench",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"bench": "autocannon -b '{\"a\":1}' -H \"Content-Type=application/json\""
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@types/body-parser": "^1.19.5",
15+
"autocannon": "^7.15.0",
16+
"body-parser": "^1.20.2"
17+
}
18+
}

0 commit comments

Comments
 (0)