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:
27
benchmarks/primes.zig
Normal file
27
benchmarks/primes.zig
Normal file
@@ -0,0 +1,27 @@
|
||||
// Prime counting benchmark
|
||||
const std = @import("std");
|
||||
|
||||
fn isPrime(n: i64) bool {
|
||||
if (n < 2) return false;
|
||||
if (n == 2) return true;
|
||||
if (@mod(n, 2) == 0) return false;
|
||||
var i: i64 = 3;
|
||||
while (i * i <= n) : (i += 2) {
|
||||
if (@mod(n, i) == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn countPrimes(max: i64) i64 {
|
||||
var count: i64 = 0;
|
||||
var i: i64 = 2;
|
||||
while (i <= max) : (i += 1) {
|
||||
if (isPrime(i)) count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
pub fn main() void {
|
||||
const count = countPrimes(10000);
|
||||
std.debug.print("Primes up to 10000: {d}\n", .{count});
|
||||
}
|
||||
Reference in New Issue
Block a user