From f2458cf2363f2054db53e8f34314d883143d6896 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Thu, 24 Aug 2023 11:49:58 +0200 Subject: [PATCH] added http.zig to the benchmarks --- wrk/http.zig/build.zig | 24 ++++++++++++++++++++++++ wrk/http.zig/build.zig.zon | 10 ++++++++++ wrk/http.zig/main.zig | 24 ++++++++++++++++++++++++ wrk/measure.sh | 8 ++++++++ wrk/measure_all.sh | 2 +- 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 wrk/http.zig/build.zig create mode 100644 wrk/http.zig/build.zig.zon create mode 100644 wrk/http.zig/main.zig diff --git a/wrk/http.zig/build.zig b/wrk/http.zig/build.zig new file mode 100644 index 0000000..26c3a22 --- /dev/null +++ b/wrk/http.zig/build.zig @@ -0,0 +1,24 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const hzzp_dep = b.dependency("httpz", .{ .target = target, .optimize = optimize }); + + // setup executable + const exe = b.addExecutable(.{ + .name = "http.zig.demo", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.addModule("httpz", hzzp_dep.module("httpz")); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } +} diff --git a/wrk/http.zig/build.zig.zon b/wrk/http.zig/build.zig.zon new file mode 100644 index 0000000..c35716f --- /dev/null +++ b/wrk/http.zig/build.zig.zon @@ -0,0 +1,10 @@ +.{ + .name = "http.zig-test", + .version = "0.0.0", + .dependencies = .{ + .httpz = .{ + .url = "https://github.com/karlseguin/http.zig/archive/6b048ee1566156b80e87a717bd1854131e1bad70.tar.gz", + .hash = "122079d444850912cd95a244ae41bc62e45013e0b414e0a920c8f5bc2033b46f9991" + }, + }, +} diff --git a/wrk/http.zig/main.zig b/wrk/http.zig/main.zig new file mode 100644 index 0000000..64ad4f1 --- /dev/null +++ b/wrk/http.zig/main.zig @@ -0,0 +1,24 @@ +const httpz = @import("httpz"); +const std = @import("std"); + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + + var server = try httpz.Server().init(allocator, .{ .port = 5882 }); + + var router = server.router(); + + // use get/post/put/head/patch/options/delete + // you can also use "all" to attach to all methods + router.get("/", getRequest); + + // start the server in the current thread, blocking. + try server.listen(); +} + +fn getRequest(req: *httpz.Request, res: *httpz.Response) !void { + // try res.json(.{ .id = req.param("id").?, .name = "Teg" }, .{}); + _ = req; + res.body = "Hello http.zig!!!"; +} diff --git a/wrk/measure.sh b/wrk/measure.sh index 5520f0a..fa9719a 100755 --- a/wrk/measure.sh +++ b/wrk/measure.sh @@ -21,6 +21,14 @@ if [ "$SUBJECT" = "zig-zap" ] ; then URL=http://127.0.0.1:3000 fi +if [ "$SUBJECT" = "http.zig" ] ; then + cd wrk/http.zig + zig build -Doptimize=ReleaseFast > /dev/null + $TSK_SRV ./zig-out/bin/http.zig.demo & + PID=$! + URL=http://127.0.0.1:5882 +fi + if [ "$SUBJECT" = "zigstd" ] ; then zig build -Doptimize=ReleaseFast wrk_zigstd > /dev/null $TSK_SRV ./zig-out/bin/wrk_zigstd & diff --git a/wrk/measure_all.sh b/wrk/measure_all.sh index 0f5bb5b..97fcd76 100755 --- a/wrk/measure_all.sh +++ b/wrk/measure_all.sh @@ -14,7 +14,7 @@ if [ "$SUBJECTS" = "README" ] ; then fi if [ -z "$SUBJECTS" ] ; then - SUBJECTS="zig-zap go python python-sanic rust-bythebook rust-bythebook-improved rust-clean rust-axum csharp cpp-beast" + SUBJECTS="zig-zap http.zig go python python-sanic rust-bythebook rust-bythebook-improved rust-clean rust-axum csharp cpp-beast" fi for S in $SUBJECTS; do