diff --git a/bench/index.md b/bench/index.md index 6fd6bb3..4482d19 100644 --- a/bench/index.md +++ b/bench/index.md @@ -1,22 +1,23 @@ -## Benchmark +# Benchmark -Below is a comparison of body-parser and milliparsec in terms of parsing a request with JSON payload. +Below are benchmarks of body-parser vs milliparsec and formidable vs milliparsec. Please take into account that these benchmarks are not entirely accurate, since they are taken on a regular desktop computer in usual conditions. -### Environment +## Environment - Node.js 22.3.0 -- System: Linux 6.9.7 +- System: Linux 6.10.10 +- CPU: Intel Core i9-13900H - Machine: Asus ROG Zephyrus G16 -### JSON parsing +## JSON parsing -#### Benchmark command: +### Benchmark command: ```sh autocannon -b '{"a":1}' -H "Content-Type=application/json" localhost:3002 # or 3003 ``` -#### Results +### Results body-parser result: @@ -24,20 +25,20 @@ 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 │ +│ Latency │ 0 ms │ 0 ms │ 0 ms │ 0 ms │ 0.01 ms │ 0.81 ms │ 258 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 │ +│ Req/Sec │ 33,055 │ 33,055 │ 44,095 │ 45,055 │ 42,820.37 │ 3,265.01 │ 33,046 │ ├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤ -│ Bytes/Sec │ 4.03 MB │ 4.03 MB │ 5.52 MB │ 5.67 MB │ 5.39 MB │ 448 kB │ 4.03 MB │ +│ Bytes/Sec │ 4.26 MB │ 4.26 MB │ 5.69 MB │ 5.81 MB │ 5.52 MB │ 421 kB │ 4.26 MB │ └───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴─────────┘ Req/Bytes counts sampled once per second. # of samples: 11 -460k requests in 11.02s, 59.3 MB read +471k requests in 11.03s, 60.8 MB read ``` milliparsec result: @@ -46,34 +47,80 @@ 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 │ +│ Latency │ 0 ms │ 0 ms │ 0 ms │ 0 ms │ 0.01 ms │ 0.64 ms │ 252 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 │ -└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴────────┘ +┌───────────┬─────────┬─────────┬─────────┬─────────┬───────────┬──────────┬─────────┐ +│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │ +├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤ +│ Req/Sec │ 50,751 │ 50,751 │ 63,423 │ 67,071 │ 63,610.19 │ 4,416.72 │ 50,739 │ +├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤ +│ Bytes/Sec │ 6.19 MB │ 6.19 MB │ 7.74 MB │ 8.18 MB │ 7.76 MB │ 538 kB │ 6.19 MB │ +└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴─────────┘ Req/Bytes counts sampled once per second. # of samples: 11 -697k requests in 11.02s, 85.1 MB rea +700k requests in 11.02s, 85.4 MB read ``` ### Verdict -milliparsec, on average, is ~34% faster. +milliparsec, on average, is ~30-40% faster. -### Multipart with files +## Multipart with files -#### Benchmark command: +### Benchmark command: ```sh autocannon -m POST --form '{ "file": { "type": "file", "path": "./file.txt" } }' localhost:3004 ``` -#### Results +### Results + +formidable result: + +``` +┌─────────┬──────┬──────┬───────┬───────┬─────────┬─────────┬────────┐ +│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │ +├─────────┼──────┼──────┼───────┼───────┼─────────┼─────────┼────────┤ +│ Latency │ 1 ms │ 8 ms │ 26 ms │ 32 ms │ 9.73 ms │ 8.81 ms │ 256 ms │ +└─────────┴──────┴──────┴───────┴───────┴─────────┴─────────┴────────┘ +┌───────────┬─────────┬─────────┬────────┬────────┬────────┬────────┬─────────┐ +│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │ +├───────────┼─────────┼─────────┼────────┼────────┼────────┼────────┼─────────┤ +│ Req/Sec │ 420 │ 420 │ 690 │ 2,517 │ 974.7 │ 627.32 │ 420 │ +├───────────┼─────────┼─────────┼────────┼────────┼────────┼────────┼─────────┤ +│ Bytes/Sec │ 83.2 kB │ 83.2 kB │ 137 kB │ 498 kB │ 193 kB │ 124 kB │ 83.2 kB │ +└───────────┴─────────┴─────────┴────────┴────────┴────────┴────────┴─────────┘ + +Req/Bytes counts sampled once per second. +# of samples: 10 + +10k requests in 10.03s, 1.93 MB read +``` + +milliparsec result: + +``` +┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬────────┐ +│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │ +├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼────────┤ +│ Latency │ 0 ms │ 0 ms │ 1 ms │ 1 ms │ 0.21 ms │ 2.15 ms │ 375 ms │ +└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴────────┘ +┌───────────┬────────┬────────┬─────────┬─────────┬─────────┬──────────┬────────┐ +│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │ +├───────────┼────────┼────────┼─────────┼─────────┼─────────┼──────────┼────────┤ +│ Req/Sec │ 6,543 │ 6,543 │ 14,607 │ 15,455 │ 13,841 │ 2,516.57 │ 6,542 │ +├───────────┼────────┼────────┼─────────┼─────────┼─────────┼──────────┼────────┤ +│ Bytes/Sec │ 1.3 MB │ 1.3 MB │ 2.89 MB │ 3.06 MB │ 2.74 MB │ 498 kB │ 1.3 MB │ +└───────────┴────────┴────────┴─────────┴─────────┴─────────┴──────────┴────────┘ + +Req/Bytes counts sampled once per second. +# of samples: 10 + +138k requests in 10.03s, 27.4 MB read +``` + +### Verdict -TBD \ No newline at end of file +milliparsec, on average, is ~1000-1200% faster. \ No newline at end of file diff --git a/bench/milliparsec-multipart.js b/bench/milliparsec-multipart.js index 0f9fa3e..75daf00 100644 --- a/bench/milliparsec-multipart.js +++ b/bench/milliparsec-multipart.js @@ -13,11 +13,6 @@ const server = createServer((req, res) => { const file = req.body.file[0] const stream = file.stream() - res.writeHead(200, { - 'Content-Type': file.type, - 'Content-Disposition': `attachment; filename="${file.name}"` - }) - // Pipe the stream to the response stream.pipeTo( new WritableStream({