1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

added http.zig to the benchmarks

This commit is contained in:
Rene Schallner 2023-08-24 11:49:58 +02:00
parent ac5a902cf6
commit f2458cf236
5 changed files with 67 additions and 1 deletions

24
wrk/http.zig/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 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);
}
}

View file

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

24
wrk/http.zig/main.zig Normal file
View file

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

View file

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

View file

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