httpp-benchmark

httpp-benchmark.git
git clone git://git.lenczewski.org/httpp-benchmark.git
Log | Files | Refs | README | LICENSE

commit 3574bd278f24d75b079722a3b5ad263d12133ef9
parent 0a8eeb6e0350c6057502689391e0eba4405c72b9
Author: cebem1nt <mineewarik@gmail.com>
Date:   Wed, 26 Nov 2025 23:16:27 -0300

Benchmark added, comments and license

Diffstat:
M.gitignore | 5+++--
Abenchmark.c | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mhttpp.h | 31+++++++++++++++++++++++++++----
3 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,2 @@ -*.out -\ No newline at end of file +*.out +benchmark +\ No newline at end of file diff --git a/benchmark.c b/benchmark.c @@ -0,0 +1,52 @@ +// A benchmark adapted from https://github.com/fukamachi/fast-http + +#include <assert.h> +#include <stdio.h> +#include <time.h> +#include <string.h> + +#define HTTPP_IMPLEMENTATION +#include "httpp.h" + +#define REQ \ +"GET /cookies HTTP/1.1\r\n" \ +"Host: 127.0.0.1:8090\r\n" \ +"Connection: keep-alive\r\n" \ +"Cache-Control: max-age=0\r\n" \ +"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" \ +"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17\r\n" \ +"Accept-Encoding: gzip,deflate,sdch\r\n" \ +"Accept-Language: en-US,en;q=0.8\r\n" \ +"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n" \ +"Cookie: name=wookie\r\n" \ +"\r\n" + +#define ITERATIONS 1000000 + +double now_seconds(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec + ts.tv_nsec / 1e9; +} + +int main(void) { + char* raw = REQ; + size_t raw_len = strlen(raw); + int i; + + double t0 = now_seconds(); + for (i = 0; i < ITERATIONS; ++i) { + httpp_req_t* req = httpp_parse_request(raw); + if (!req) { + fprintf(stderr, "parse failed at iter %d\n", i); + return 1; + } + + httpp_req_free(req); + } + double t1 = now_seconds(); + + printf("Elapsed %f seconds.\n", t1 - t0); + return 0; +} diff --git a/httpp.h b/httpp.h @@ -6,7 +6,7 @@ * * Chunked transfer is not really supported * - * TODO Folded headers nor handled + * TODO Folded headers aren't handled. */ #include <stddef.h> @@ -118,7 +118,6 @@ int httpp_res_set_body(httpp_res_t* res, char* body); // strdup and res->body = void httpp_res_free(httpp_res_t* res); char* httpp_res_to_raw(httpp_res_t* res); -#define HTTPP_IMPLEMENTATION #ifdef HTTPP_IMPLEMENTATION #define trim(str) do { ltrim(str); rtrim(str); } while (0) @@ -522,4 +521,28 @@ char* httpp_res_to_raw(httpp_res_t* res) return out; } -#endif // HTTPP_IMPLEMENTATION -\ No newline at end of file +#endif // HTTPP_IMPLEMENTATION + +/* +* MIT License +* +* Copyright (c) 2025 Mint +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +\ No newline at end of file