From 2413f17bbdbd8e8555ef7f31d690fcba4aab95e0 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Sun, 3 Mar 2024 10:16:34 +0800 Subject: [PATCH 1/2] add http.zig to benchmarks --- wrk/measure.sh | 9 +++++++++ wrk/zighttpz/build.zig | 24 ++++++++++++++++++++++++ wrk/zighttpz/build.zig.zon | 11 +++++++++++ wrk/zighttpz/main.zig | 23 +++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 wrk/zighttpz/build.zig create mode 100644 wrk/zighttpz/build.zig.zon create mode 100644 wrk/zighttpz/main.zig diff --git a/wrk/measure.sh b/wrk/measure.sh index 5520f0ac..9a378058 100755 --- a/wrk/measure.sh +++ b/wrk/measure.sh @@ -28,6 +28,15 @@ if [ "$SUBJECT" = "zigstd" ] ; then URL=http://127.0.0.1:3000 fi +if [ "$SUBJECT" = "zighttpz" ] ; then + pushd wrk/zighttpz + zig build -Doptimize=ReleaseFast > /dev/null + $TSK_SRV ../../zig-out/bin/wrk & + PID=$! + URL=http://127.0.0.1:3000 + popd +fi + if [ "$SUBJECT" = "go" ] ; then cd wrk/go && go build main.go $TSK_SRV ./main & diff --git a/wrk/zighttpz/build.zig b/wrk/zighttpz/build.zig new file mode 100644 index 00000000..4d058324 --- /dev/null +++ b/wrk/zighttpz/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 httpz_dep = b.dependency("httpz", .{ .target = target, .optimize = optimize }); + + // setup executable + const exe = b.addExecutable(.{ + .name = "wrk_zighttpz", + .root_source_file = .{ .path = "main.zig" }, + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("httpz", httpz_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/zighttpz/build.zig.zon b/wrk/zighttpz/build.zig.zon new file mode 100644 index 00000000..4beaf3ca --- /dev/null +++ b/wrk/zighttpz/build.zig.zon @@ -0,0 +1,11 @@ +.{ + .name = "http.zig-test", + .version = "0.0.0", + .paths = .{""}, + .dependencies = .{ + .httpz = .{ + .url = "https://github.com/karlseguin/http.zig/archive/ec59a3daccd5145601a18786ef033f4ff2392520.tar.gz", + .hash = "12209ba122606b92c7dfb0a7dfb9da5520ffa5df007b976774e91d01b2040b25fae4" + }, + }, +} diff --git a/wrk/zighttpz/main.zig b/wrk/zighttpz/main.zig new file mode 100644 index 00000000..64f463d7 --- /dev/null +++ b/wrk/zighttpz/main.zig @@ -0,0 +1,23 @@ +const std = @import("std"); +const httpz = @import("httpz"); + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{ + .thread_safe = true, + }){}; + const allocator = gpa.allocator(); + + var server = try httpz.Server().init(allocator, .{ + .port = 3000, + .address = "127.0.0.1", + }); + defer server.deinit(); + var router = server.router(); + + router.get("/", index); + try server.listen(); +} + +fn index(_: *httpz.Request, res: *httpz.Response) !void { + res.body = "HI FROM ZIG-HTTPZ"; +} From 9f56ab40f3fbce72f6118515676e9f8882481ceb Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 24 Apr 2024 08:50:35 +0800 Subject: [PATCH 2/2] update httpz dependency for zig 0.12 --- wrk/zighttpz/build.zig.zon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrk/zighttpz/build.zig.zon b/wrk/zighttpz/build.zig.zon index 4beaf3ca..2f4b3889 100644 --- a/wrk/zighttpz/build.zig.zon +++ b/wrk/zighttpz/build.zig.zon @@ -4,8 +4,8 @@ .paths = .{""}, .dependencies = .{ .httpz = .{ - .url = "https://github.com/karlseguin/http.zig/archive/ec59a3daccd5145601a18786ef033f4ff2392520.tar.gz", - .hash = "12209ba122606b92c7dfb0a7dfb9da5520ffa5df007b976774e91d01b2040b25fae4" + .url = "https://github.com/karlseguin/http.zig/archive/zig-0.12.tar.gz", + .hash = "12209b7426293ebe5075b930ae6029c009bfb6deb7ff92b9d69e28463abd14ad03da" }, }, }