Files
lux/benchmarks/http_server.zig
Brandon Lucas 49ab70829a feat: add comprehensive benchmark suite with flake commands
- Add nix flake commands: bench, bench-poop, bench-quick
- Add hyperfine and poop to devShell
- Document benchmark results with hyperfine/poop output
- Explain why Lux matches C (gcc's recursion optimization)
- Add HTTP server benchmark files (C, Rust, Zig)
- Add Zig versions of all benchmarks

Key findings:
- Lux (compiled): 28.1ms - fastest
- C (gcc -O3): 29.0ms - 1.03x slower
- Rust: 41.2ms - 1.47x slower
- Zig: 47.0ms - 1.67x slower

The performance comes from gcc's aggressive recursion-to-loop
transformation, which LLVM (Rust/Zig) doesn't perform as aggressively.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 05:53:10 -05:00

26 lines
877 B
Zig

// Minimal HTTP server benchmark - Zig version (single-threaded)
// Compile: zig build-exe -O ReleaseFast http_server.zig
// Test: wrk -t2 -c50 -d5s http://localhost:8082/
const std = @import("std");
const net = std.net;
const response = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}";
pub fn main() !void {
const address = net.Address.initIp4(.{ 0, 0, 0, 0 }, 8082);
var server = try address.listen(.{ .reuse_address = true });
defer server.deinit();
std.debug.print("Zig HTTP server listening on port 8082\n", .{});
while (true) {
var connection = server.accept() catch continue;
defer connection.stream.close();
var buf: [1024]u8 = undefined;
_ = connection.stream.read(&buf) catch continue;
_ = connection.stream.write(response) catch continue;
}
}