Skip to content

Commit

Permalink
fixed wrk_zigstd. It compiles but can't handle wrk :(
Browse files Browse the repository at this point in the history
  • Loading branch information
renerocksai committed May 19, 2023
1 parent 7154588 commit 0c18565
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions targets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ serve
hello_json
endpoint
wrk
wrk_zigstd
mustache
endpoint_auth
http_params
Expand Down
23 changes: 16 additions & 7 deletions wrk/zigstd/main.zig
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
const std = @import("std");

pub fn main() !void {
const allocator = std.heap.page_allocator;
var gpa = std.heap.GeneralPurposeAllocator(.{
.thread_safe = true,
}){};
var allocator = gpa.allocator();

var server = std.http.Server.init(allocator, .{
.reuse_address = true,
});
defer server.deinit();

const address = try std.net.Address.parseIp("127.0.0.1", 3000);
try server.listen(address);

const max_header_size = 8192;

while (true) {
var res = try server.accept(.{ .dynamic = max_header_size });
const start_time = std.time.nanoTimestamp();
var res = try server.accept(.{
.allocator = allocator,
.header_strategy = .{ .dynamic = max_header_size },
});
// const start_time = std.time.nanoTimestamp();
defer res.deinit();
defer res.reset();
defer _ = res.reset();
try res.wait();

const server_body: []const u8 = "HI FROM ZIG STD!\n";
Expand All @@ -27,8 +36,8 @@ pub fn main() !void {
_ = try res.readAll(&buf);
_ = try res.writer().writeAll(server_body);
try res.finish();
const end_time = std.time.nanoTimestamp();
const diff = end_time - start_time;
std.debug.print("{d}\n", .{diff});
// const end_time = std.time.nanoTimestamp();
// const diff = end_time - start_time;
// std.debug.print("{d}\n", .{diff});
}
}

0 comments on commit 0c18565

Please sign in to comment.