Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 179:8d17f6e6e290 | 183:a8976a008a9d |
|---|---|
| 1 /** | |
| 2 * Seobeo HTTP Framework Benchmark | |
| 3 * | |
| 4 * Implements the 3 required endpoints: | |
| 5 * - GET / -> "Hi" | |
| 6 * - GET /id/:id -> "{id} {name}" with x-powered-by header | |
| 7 * - POST /json -> mirrors JSON body | |
| 8 */ | |
| 9 | |
| 10 #include "seobeo/seobeo.h" | |
| 11 #include <stdio.h> | |
| 12 #include <stdlib.h> | |
| 13 #include <string.h> | |
| 14 | |
| 15 // GET / - Return "Hi" | |
| 16 Seobeo_Request_Entry* GetIndex(Seobeo_Request_Entry *p_req, Dowa_Arena *p_arena) | |
| 17 { | |
| 18 (void)p_req; | |
| 19 | |
| 20 Seobeo_Request_Entry *p_resp = NULL; | |
| 21 Dowa_HashMap_Push_Arena(p_resp, "status", "200", p_arena); | |
| 22 Dowa_HashMap_Push_Arena(p_resp, "content-type", "text/plain", p_arena); | |
| 23 Dowa_HashMap_Push_Arena(p_resp, "body", "Hi", p_arena); | |
| 24 | |
| 25 return p_resp; | |
| 26 } | |
| 27 | |
| 28 // GET /id/:id - Return "{id} {name}" with x-powered-by header | |
| 29 Seobeo_Request_Entry* GetId(Seobeo_Request_Entry *p_req, Dowa_Arena *p_arena) | |
| 30 { | |
| 31 // Get the :id param (stored as ":id" key) | |
| 32 void *p_id_kv = Dowa_HashMap_Get_Ptr(p_req, ":id"); | |
| 33 const char *id = p_id_kv ? ((Seobeo_Request_Entry*)p_id_kv)->value : ""; | |
| 34 | |
| 35 // Get the query param "name" (stored as "query_name") | |
| 36 void *p_name_kv = Dowa_HashMap_Get_Ptr(p_req, "query_name"); | |
| 37 const char *name = p_name_kv ? ((Seobeo_Request_Entry*)p_name_kv)->value : ""; | |
| 38 | |
| 39 // Build response body: "{id} {name}" | |
| 40 size_t body_len = strlen(id) + 1 + strlen(name) + 1; | |
| 41 char *body = Dowa_Arena_Allocate(p_arena, body_len); | |
| 42 snprintf(body, body_len, "%s %s", id, name); | |
| 43 | |
| 44 Seobeo_Request_Entry *p_resp = NULL; | |
| 45 Dowa_HashMap_Push_Arena(p_resp, "status", "200", p_arena); | |
| 46 Dowa_HashMap_Push_Arena(p_resp, "content-type", "text/plain", p_arena); | |
| 47 Dowa_HashMap_Push_Arena(p_resp, "x-powered-by", "benchmark", p_arena); | |
| 48 Dowa_HashMap_Push_Arena(p_resp, "body", body, p_arena); | |
| 49 | |
| 50 return p_resp; | |
| 51 } | |
| 52 | |
| 53 // POST /json - Mirror the JSON body | |
| 54 Seobeo_Request_Entry* PostJson(Seobeo_Request_Entry *p_req, Dowa_Arena *p_arena) | |
| 55 { | |
| 56 // Get the request body | |
| 57 void *p_body_kv = Dowa_HashMap_Get_Ptr(p_req, "Body"); | |
| 58 const char *body = p_body_kv ? ((Seobeo_Request_Entry*)p_body_kv)->value : "{}"; | |
| 59 | |
| 60 Seobeo_Request_Entry *p_resp = NULL; | |
| 61 Dowa_HashMap_Push_Arena(p_resp, "status", "200", p_arena); | |
| 62 Dowa_HashMap_Push_Arena(p_resp, "content-type", "application/json", p_arena); | |
| 63 Dowa_HashMap_Push_Arena(p_resp, "body", (char*)body, p_arena); | |
| 64 | |
| 65 return p_resp; | |
| 66 } | |
| 67 | |
| 68 int main() | |
| 69 { | |
| 70 // Initialize router | |
| 71 Seobeo_Router_Init(); | |
| 72 | |
| 73 // Register routes | |
| 74 Seobeo_Router_Register("GET", "/", GetIndex); | |
| 75 Seobeo_Router_Register("GET", "/id/:id", GetId); | |
| 76 Seobeo_Router_Register("POST", "/json", PostJson); | |
| 77 | |
| 78 // Start server on port 3000 using edge-triggered I/O | |
| 79 // Using EDGE mode for maximum performance (epoll/kqueue) | |
| 80 Seobeo_Web_Server_Start(NULL, "3000", SEOBEO_MODE_EDGE, 4); | |
| 81 | |
| 82 return 0; | |
| 83 } |