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>
This commit is contained in:
47
benchmarks/http_server.c
Normal file
47
benchmarks/http_server.c
Normal file
@@ -0,0 +1,47 @@
|
||||
// Minimal HTTP server benchmark - C version (single-threaded, poll-based)
|
||||
// Compile: gcc -O3 -o http_c http_server.c
|
||||
// Test: wrk -t2 -c50 -d5s http://localhost:8080/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#define PORT 8080
|
||||
#define RESPONSE "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}"
|
||||
|
||||
int main() {
|
||||
int server_fd, client_fd;
|
||||
struct sockaddr_in address;
|
||||
int opt = 1;
|
||||
char buffer[1024];
|
||||
socklen_t addrlen = sizeof(address);
|
||||
|
||||
server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||
setsockopt(server_fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
address.sin_port = htons(PORT);
|
||||
|
||||
bind(server_fd, (struct sockaddr*)&address, sizeof(address));
|
||||
listen(server_fd, 1024);
|
||||
|
||||
printf("C HTTP server listening on port %d\n", PORT);
|
||||
fflush(stdout);
|
||||
|
||||
while (1) {
|
||||
client_fd = accept(server_fd, (struct sockaddr*)&address, &addrlen);
|
||||
if (client_fd < 0) continue;
|
||||
|
||||
read(client_fd, buffer, sizeof(buffer));
|
||||
write(client_fd, RESPONSE, strlen(RESPONSE));
|
||||
close(client_fd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user