Mercurial
diff benchmark/bun-http-framework-benchmark/src/c/seobeo.c @ 183:a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 21:19:08 -0800 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/bun-http-framework-benchmark/src/c/seobeo.c Fri Jan 23 21:19:08 2026 -0800 @@ -0,0 +1,83 @@ +/** + * Seobeo HTTP Framework Benchmark + * + * Implements the 3 required endpoints: + * - GET / -> "Hi" + * - GET /id/:id -> "{id} {name}" with x-powered-by header + * - POST /json -> mirrors JSON body + */ + +#include "seobeo/seobeo.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +// GET / - Return "Hi" +Seobeo_Request_Entry* GetIndex(Seobeo_Request_Entry *p_req, Dowa_Arena *p_arena) +{ + (void)p_req; + + Seobeo_Request_Entry *p_resp = NULL; + Dowa_HashMap_Push_Arena(p_resp, "status", "200", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "content-type", "text/plain", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "body", "Hi", p_arena); + + return p_resp; +} + +// GET /id/:id - Return "{id} {name}" with x-powered-by header +Seobeo_Request_Entry* GetId(Seobeo_Request_Entry *p_req, Dowa_Arena *p_arena) +{ + // Get the :id param (stored as ":id" key) + void *p_id_kv = Dowa_HashMap_Get_Ptr(p_req, ":id"); + const char *id = p_id_kv ? ((Seobeo_Request_Entry*)p_id_kv)->value : ""; + + // Get the query param "name" (stored as "query_name") + void *p_name_kv = Dowa_HashMap_Get_Ptr(p_req, "query_name"); + const char *name = p_name_kv ? ((Seobeo_Request_Entry*)p_name_kv)->value : ""; + + // Build response body: "{id} {name}" + size_t body_len = strlen(id) + 1 + strlen(name) + 1; + char *body = Dowa_Arena_Allocate(p_arena, body_len); + snprintf(body, body_len, "%s %s", id, name); + + Seobeo_Request_Entry *p_resp = NULL; + Dowa_HashMap_Push_Arena(p_resp, "status", "200", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "content-type", "text/plain", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "x-powered-by", "benchmark", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "body", body, p_arena); + + return p_resp; +} + +// POST /json - Mirror the JSON body +Seobeo_Request_Entry* PostJson(Seobeo_Request_Entry *p_req, Dowa_Arena *p_arena) +{ + // Get the request body + void *p_body_kv = Dowa_HashMap_Get_Ptr(p_req, "Body"); + const char *body = p_body_kv ? ((Seobeo_Request_Entry*)p_body_kv)->value : "{}"; + + Seobeo_Request_Entry *p_resp = NULL; + Dowa_HashMap_Push_Arena(p_resp, "status", "200", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "content-type", "application/json", p_arena); + Dowa_HashMap_Push_Arena(p_resp, "body", (char*)body, p_arena); + + return p_resp; +} + +int main() +{ + // Initialize router + Seobeo_Router_Init(); + + // Register routes + Seobeo_Router_Register("GET", "/", GetIndex); + Seobeo_Router_Register("GET", "/id/:id", GetId); + Seobeo_Router_Register("POST", "/json", PostJson); + + // Start server on port 3000 using edge-triggered I/O + // Using EDGE mode for maximum performance (epoll/kqueue) + Seobeo_Web_Server_Start(NULL, "3000", SEOBEO_MODE_EDGE, 4); + + return 0; +}