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:
2026-02-16 05:53:10 -05:00
parent 8a001a8f26
commit 49ab70829a
10 changed files with 543 additions and 166 deletions

View File

@@ -24,6 +24,9 @@
cargo-edit
pkg-config
openssl
# Benchmark tools
hyperfine
poop
];
RUST_BACKTRACE = "1";
@@ -67,6 +70,88 @@
doCheck = false;
};
# Benchmark scripts
apps = {
# Run hyperfine benchmark comparison
bench = {
type = "app";
program = toString (pkgs.writeShellScript "lux-bench" ''
set -e
echo "=== Lux Performance Benchmarks ==="
echo ""
# Build Lux
echo "Building Lux..."
cd ${self}
${pkgs.cargo}/bin/cargo build --release 2>/dev/null
# Compile benchmarks
echo "Compiling benchmark binaries..."
./target/release/lux compile benchmarks/fib.lux -o /tmp/fib_lux 2>/dev/null
${pkgs.gcc}/bin/gcc -O3 benchmarks/fib.c -o /tmp/fib_c 2>/dev/null
${pkgs.rustc}/bin/rustc -C opt-level=3 -C lto benchmarks/fib.rs -o /tmp/fib_rust 2>/dev/null
${pkgs.zig}/bin/zig build-exe benchmarks/fib.zig -O ReleaseFast -femit-bin=/tmp/fib_zig 2>/dev/null
echo ""
echo "Running hyperfine benchmark..."
echo ""
${pkgs.hyperfine}/bin/hyperfine --warmup 3 --runs 10 \
--export-markdown /tmp/bench_results.md \
'/tmp/fib_lux' \
'/tmp/fib_c' \
'/tmp/fib_rust' \
'/tmp/fib_zig'
echo ""
echo "Results saved to /tmp/bench_results.md"
'');
};
# Run poop benchmark for detailed CPU metrics
bench-poop = {
type = "app";
program = toString (pkgs.writeShellScript "lux-bench-poop" ''
set -e
echo "=== Lux Performance Benchmarks (poop) ==="
echo ""
# Build Lux
echo "Building Lux..."
cd ${self}
${pkgs.cargo}/bin/cargo build --release 2>/dev/null
# Compile benchmarks
echo "Compiling benchmark binaries..."
./target/release/lux compile benchmarks/fib.lux -o /tmp/fib_lux 2>/dev/null
${pkgs.gcc}/bin/gcc -O3 benchmarks/fib.c -o /tmp/fib_c 2>/dev/null
${pkgs.rustc}/bin/rustc -C opt-level=3 -C lto benchmarks/fib.rs -o /tmp/fib_rust 2>/dev/null
${pkgs.zig}/bin/zig build-exe benchmarks/fib.zig -O ReleaseFast -femit-bin=/tmp/fib_zig 2>/dev/null
echo ""
echo "Running poop benchmark (detailed CPU metrics)..."
echo ""
${pkgs.poop}/bin/poop '/tmp/fib_c' '/tmp/fib_lux' '/tmp/fib_rust' '/tmp/fib_zig'
'');
};
# Quick benchmark (just Lux vs C)
bench-quick = {
type = "app";
program = toString (pkgs.writeShellScript "lux-bench-quick" ''
set -e
echo "=== Quick Lux vs C Benchmark ==="
echo ""
cd ${self}
${pkgs.cargo}/bin/cargo build --release 2>/dev/null
./target/release/lux compile benchmarks/fib.lux -o /tmp/fib_lux 2>/dev/null
${pkgs.gcc}/bin/gcc -O3 benchmarks/fib.c -o /tmp/fib_c 2>/dev/null
${pkgs.hyperfine}/bin/hyperfine --warmup 3 '/tmp/fib_lux' '/tmp/fib_c'
'');
};
};
}
);
}