-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch from prettier/eslint to biome, use
node:
protocol, add bench…
…mark
- Loading branch information
1 parent
0d58fa4
commit d197307
Showing
18 changed files
with
1,719 additions
and
889 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
{ | ||
"biome.enabled": true, | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"prettier.enable": false, | ||
"eslint.enable": false, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": "always" | ||
}, | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"[typescript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
} | ||
} |
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
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,15 @@ | ||
// @ts-check | ||
|
||
import bodyParser from 'body-parser' | ||
import { createServer } from 'node:http' | ||
|
||
const mw = bodyParser.json() | ||
|
||
const server = createServer((req, res) => { | ||
mw(req, res, () => { | ||
// @ts-expect-error added by body parser | ||
res.end(JSON.stringify(req.body)) | ||
}) | ||
}) | ||
|
||
server.listen(3002) |
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,65 @@ | ||
## Benchmark | ||
|
||
Below is a comparison of body-parser and milliparsec in terms of parsing a request with JSON payload. | ||
|
||
### Environment | ||
|
||
- Node.js 22.3.0 | ||
- System: Linux 6.9.7 | ||
- Machine: Asus ROG Zephyrus G16 | ||
|
||
### Benchmark command: | ||
|
||
```sh | ||
autocannon -b '{"a":1}' -H "Content-Type=application/json" localhost:3002 # or 3003 | ||
``` | ||
|
||
### Results | ||
|
||
body-parser result: | ||
|
||
``` | ||
┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐ | ||
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │ | ||
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤ | ||
│ Latency │ 0 ms │ 0 ms │ 0 ms │ 0 ms │ 0.01 ms │ 0.79 ms │ 251 ms │ | ||
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘ | ||
┌───────────┬─────────┬─────────┬─────────┬─────────┬───────────┬──────────┬─────────┐ | ||
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │ | ||
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤ | ||
│ Req/Sec │ 31,231 │ 31,231 │ 42,815 │ 43,935 │ 41,823.28 │ 3,470.88 │ 31,224 │ | ||
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤ | ||
│ Bytes/Sec │ 4.03 MB │ 4.03 MB │ 5.52 MB │ 5.67 MB │ 5.39 MB │ 448 kB │ 4.03 MB │ | ||
└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴─────────┘ | ||
Req/Bytes counts sampled once per second. | ||
# of samples: 11 | ||
460k requests in 11.02s, 59.3 MB read | ||
``` | ||
|
||
milliparsec result: | ||
|
||
``` | ||
┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐ | ||
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │ | ||
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤ | ||
│ Latency │ 0 ms │ 0 ms │ 0 ms │ 0 ms │ 0.01 ms │ 0.65 ms │ 254 ms │ | ||
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘ | ||
┌───────────┬─────────┬─────────┬─────────┬─────────┬───────────┬──────────┬────────┐ | ||
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │ | ||
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼────────┤ | ||
│ Req/Sec │ 52,511 │ 52,511 │ 63,007 │ 67,455 │ 63,397.82 │ 4,255.42 │ 52,480 │ | ||
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼────────┤ | ||
│ Bytes/Sec │ 6.41 MB │ 6.41 MB │ 7.69 MB │ 8.23 MB │ 7.74 MB │ 519 kB │ 6.4 MB │ | ||
└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴────────┘ | ||
Req/Bytes counts sampled once per second. | ||
# of samples: 11 | ||
697k requests in 11.02s, 85.1 MB rea | ||
``` | ||
|
||
## Verdict | ||
|
||
milliparsec, on average, is ~34% faster. |
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,15 @@ | ||
// @ts-check | ||
|
||
import { createServer } from 'node:http' | ||
import * as bodyParser from '../dist/index.js' | ||
|
||
const mw = bodyParser.json() | ||
|
||
const server = createServer((req, res) => { | ||
mw(req, res, () => { | ||
// @ts-expect-error added by body parser | ||
res.end(JSON.stringify(req.body)) | ||
}) | ||
}) | ||
|
||
server.listen(3003) |
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,18 @@ | ||
{ | ||
"name": "bench", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"bench": "autocannon -b '{\"a\":1}' -H \"Content-Type=application/json\"" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/body-parser": "^1.19.5", | ||
"autocannon": "^7.15.0", | ||
"body-parser": "^1.20.2" | ||
} | ||
} |
Oops, something went wrong.