clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.gitCommit d272dc589e30
tarballunverified4 files changed+160-0
@@ -0,0 +1,47 @@+# Large :b:oke ---I mean...benchmark, for stress testing+let+ # Generate large list+ range = start: end:+ if start >= end+ then []+ else [start] ++ range (start + 1) end;++ # Deep nesting+ deepNest = {a = {b = {c = {d = {e = {f = 42;};};};};};};++ # Large attrset+ largeAttrs = {+ a1 = 1;+ a2 = 2;+ a3 = 3;+ a4 = 4;+ a5 = 5;+ a6 = 6;+ a7 = 7;+ a8 = 8;+ a9 = 9;+ a10 = 10;+ b1 = 11;+ b2 = 12;+ b3 = 13;+ b4 = 14;+ b5 = 15;+ b6 = 16;+ b7 = 17;+ b8 = 18;+ b9 = 19;+ b10 = 20;+ };++ # Recursive attrset+ recursive = rec {+ x = 10;+ y = x * 2;+ z = y + x;+ result = z * 3;+ };+in {+ list_100 = range 1 100;+ deep = deepNest.a.b.c.d.e.f;+ inherit largeAttrs recursive;+}@@ -0,0 +1,31 @@+let+ # Recursive fibonacci (not memoized)+ fib = n:+ if n <= 1+ then n+ else fib (n - 1) + fib (n - 2);++ # List operations+ numbers = [1 2 3 4 5 6 7 8 9 10];+ doubled = builtins.map (x: x * 2) numbers;++ # Attrset operations+ base = {+ a = 1;+ b = 2;+ c = 3;+ };+ extended =+ base+ // {+ d = 4;+ e = 5;+ };++ # String operations+ greeting = "Hello";+ message = "${greeting}, World!";+in {+ fibonacci_10 = fib 10;+ inherit doubled extended message;+}@@ -0,0 +1,69 @@+#!/usr/bin/env bash+set -e++echo ""++PLUGIN_PATH="$(pwd)/build/nix-ir-plugin.so"+BENCH_DIR="$(pwd)/tests/benchmark"+IRC_BIN="$(pwd)/build/nix-irc"++# Colors for output+GREEN='\033[0;32m'+BLUE='\033[0;34m'+NC='\033[0m' # No Color++run_benchmark() {+ local name="$1"+ local file="$2"++ echo -e "${BLUE}Benchmark: $name${NC}"+ echo "----------------------------------------"++ # 1. Parse + Compile Time (nix-irc)+ echo -n " Parse + Compile: "+ local compile_output=$( (time "$IRC_BIN" "$file" /tmp/bench.nixir 2>&1) 2>&1)+ local compile_time=$(echo "$compile_output" | grep "real" | awk '{print $2}')+ echo -e "${GREEN}$compile_time${NC}"++ # 2. IR Size+ if [ -f /tmp/bench.nixir ]; then+ local ir_size=$(stat -f%z /tmp/bench.nixir 2>/dev/null || stat -c%s /tmp/bench.nixir 2>/dev/null)+ echo -e " IR Bundle Size: ${GREEN}${ir_size} bytes${NC}"+ fi++ # 3. Native Nix evaluation time+ echo -n " Native Eval: "+ local native_time=$( (time nix-instantiate --eval --strict "$file" >/dev/null 2>&1) 2>&1 | grep "real" | awk '{print $2}')+ echo -e "${GREEN}$native_time${NC}"++ # 4. With Plugin evaluation time+ echo -n " Plugin Eval: "+ local plugin_time=$( (time nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict "$file" >/dev/null 2>&1) 2>&1 | grep "real" | awk '{print $2}')+ echo -e "${GREEN}$plugin_time${NC}"++ echo ""+}++echo "# Running benchmarks..."+echo ""++run_benchmark "Simple Expressions" "$BENCH_DIR/simple.nix"+run_benchmark "Medium Complexity" "$BENCH_DIR/medium.nix"+run_benchmark "Large/Complex" "$BENCH_DIR/large.nix"++# File size comparison+echo -e "${BLUE}File Size Comparison${NC}"+echo "----------------------------------------"+testdir=$(mktemp -d)++for f in "$BENCH_DIR"/*.nix; do+ nixsize=$(stat -c%s "$f" 2>/dev/null || stat -f%z "$f" 2>/dev/null)+ base=$(basename "$f" .nix)+ irfile="${testdir}/${base}.nixir"+ $IRC_BIN "$f" "$irfile" >/dev/null 2>&1+ if [ -f "$irfile" ]; then+ irsize=$(stat -c%s "$irfile" 2>/dev/null || stat -f%z "$irfile" 2>/dev/null)+ ratio=$((irsize * 100 / nixsize))+ echo " $base: ${nixsize}B => ${irsize}B (${ratio}% of source)"+ fi+done@@ -0,0 +1,13 @@+let+ x = 10;+ y = 20;+ z = x + y;+in {+ result = z * 2;+ list = [1 2 3 4 5];+ attrs = {+ a = 1;+ b = 2;+ c = 3;+ };+}