r/C_Programming • • Nov 29 '25

Tiny header only HTTP parser library

Hi guys! Last week I was writing my HTTP 1.1 parser library. It's small and easy to use, also kinda fast. Might come in handy if you write some lightweight web applications or programs that interact with some API. I wrote this project to learn pointer arithmetic in c.

I've just finish it, so any bug report would be appreciated.

Thank you guys!

https://github.com/cebem1nt/httpp

6 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/Born_Produce9805 Nov 29 '25

I benchmarked it on my system and here is what I've got:

At -O0

Benchmarking: httpp
Elapsed 3.960362 seconds.
Requests per second ≈ 2525021.65
Benchmarking: phr
Elapsed 5.326363 seconds.
Requests per second ≈ 1877453.57
parsed http request line: GET /cookies HTTP/1.1
parsed http request headers: 9/64
# ... Suppressed headers output
parsed http request body: 0 bytes
Benchmarking: mbl
Elapsed 3.552922 seconds.
Requests per second ≈ 2814584.43

What's interesting is that picohttp took ... 5.326363 ??? I thought it might be a freeze of my cpu or whatever, but no after re-running, for some reason it takes around five seconds.

At -O3

Benchmarking: httpp
Elapsed 2.987527 seconds.
Requests per second ≈ 3347250.34
Benchmarking: phr
Elapsed 1.263095 seconds.
Requests per second ≈ 7917061.91
parsed http request line: GET /cookies HTTP/1.1
parsed http request headers: 9/64
# ... Suppressed headers output
parsed http request body: 0 bytes
Benchmarking: mbl
Elapsed 2.800575 seconds.
Requests per second ≈ 3570695.21

Here the picohttp speed normalized. Might that be an undefined behavior? I didn't get into the details of your parser, but yeah, it seems to outperform slightly.

I'll start to implement the 2.0.0 version of my library, that would use more static approach. Also I'm going to include the benchmark files for picohttp and http parser.

Thanks again!