brewery
notashelf /
d272dc589e306e450d57d30218994ecfe45a6bd6

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git

Commit d272dc589e30

tarball

NotAShelf <raf@notashelf.dev> · 2026-04-24 20:13 UTC

unverified4 files changed+160-0
tests: initial benchmarking setup

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: If0ed2dd4279abf155a8ddc678ca047736a6a6964
diff --git a/tests/benchmark/large.nix b/tests/benchmark/large.nixnew file mode 100644index 0000000..ffd7e22--- /dev/null+++ b/tests/benchmark/large.nix@@ -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;+}diff --git a/tests/benchmark/medium.nix b/tests/benchmark/medium.nixnew file mode 100644index 0000000..f8db9e9--- /dev/null+++ b/tests/benchmark/medium.nix@@ -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;+}diff --git a/tests/benchmark/run_benchmarks.sh b/tests/benchmark/run_benchmarks.shnew file mode 100755index 0000000..49c9ba8--- /dev/null+++ b/tests/benchmark/run_benchmarks.sh@@ -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+donediff --git a/tests/benchmark/simple.nix b/tests/benchmark/simple.nixnew file mode 100644index 0000000..aec2fc9--- /dev/null+++ b/tests/benchmark/simple.nix@@ -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;+  };+}