Files
lux/benchmarks/run_benchmarks.sh
Brandon Lucas 2960dd6538 feat: add benchmarks and enhance LSP completions/hover
Benchmarks:
- Add fib, list_ops, primes benchmarks comparing Lux vs Node.js vs Rust
- Lux matches Rust performance and is 8-30x faster than Node.js
- Add docs/benchmarks.md documenting results

LSP improvements:
- Context-aware completions (module access vs general)
- Add List, String, Option, Result, Console, Math method completions
- Add type and builtin completions
- Hover now shows type signatures and documentation for known symbols
- Hover returns formatted markdown with code blocks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:23:35 -05:00

74 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Benchmark runner for Lux vs other languages
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
echo "=== Lux Language Benchmarks ==="
echo "Date: $(date)"
echo ""
# Build Lux compiler in release mode
echo "Building Lux compiler..."
cargo build --release 2>/dev/null
# Function to time a command using /usr/bin/time or bash time
time_cmd() {
local name="$1"
shift
# Use bash's time with TIMEFORMAT
TIMEFORMAT="%R"
local elapsed=$( { time "$@" > /dev/null 2>&1; } 2>&1 )
printf " %-20s %8.3f s\n" "$name" "$elapsed"
}
# Fibonacci benchmark
echo "=== Fibonacci (fib(35)) ==="
# Lux compiled
echo "Compiling Lux (native)..."
cargo run --release -- compile benchmarks/fib.lux -o /tmp/fib_lux 2>/dev/null
time_cmd "Lux (native)" /tmp/fib_lux
# Node.js
time_cmd "Node.js" node benchmarks/fib.js
# Rust (compile + run)
echo "Compiling Rust..."
rustc -O benchmarks/fib.rs -o /tmp/fib_rust 2>/dev/null
time_cmd "Rust (native)" /tmp/fib_rust
echo ""
# List operations benchmark
echo "=== List Operations (10k elements) ==="
cargo run --release -- compile benchmarks/list_ops.lux -o /tmp/list_ops_lux 2>/dev/null
time_cmd "Lux (native)" /tmp/list_ops_lux
time_cmd "Node.js" node benchmarks/list_ops.js
rustc -O benchmarks/list_ops.rs -o /tmp/list_ops_rust 2>/dev/null
time_cmd "Rust (native)" /tmp/list_ops_rust
echo ""
# Primes benchmark
echo "=== Prime Counting (up to 10000) ==="
cargo run --release -- compile benchmarks/primes.lux -o /tmp/primes_lux 2>/dev/null
time_cmd "Lux (native)" /tmp/primes_lux
time_cmd "Node.js" node benchmarks/primes.js
rustc -O benchmarks/primes.rs -o /tmp/primes_rust 2>/dev/null
time_cmd "Rust (native)" /tmp/primes_rust
echo ""
echo "=== Summary ==="
echo "Lux compiles to native code via C, comparable to other AOT-compiled languages."
echo "Performance depends on optimization level and runtime overhead."