1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

add http.zig to benchmarks

This commit is contained in:
Karl Seguin 2024-03-03 10:16:34 +08:00
parent 1cb29622e7
commit 2413f17bbd
4 changed files with 67 additions and 0 deletions

View file

@ -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 &

24
wrk/zighttpz/build.zig Normal file
View file

@ -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);
}
}

View file

@ -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"
},
},
}

23
wrk/zighttpz/main.zig Normal file
View file

@ -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";
}