brewery
notashelf /
d272dc589e306e450d57d30218994ecfe45a6bd6

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git
tests/benchmark/run_benchmarks.shBash69 lines2.1 KB
1
#!/usr/bin/env bash
2
set -e
3
4
echo ""
5
6
PLUGIN_PATH="$(pwd)/build/nix-ir-plugin.so"
7
BENCH_DIR="$(pwd)/tests/benchmark"
8
IRC_BIN="$(pwd)/build/nix-irc"
9
10
# Colors for output
11
GREEN='\033[0;32m'
12
BLUE='\033[0;34m'
13
NC='\033[0m' # No Color
14
15
run_benchmark() {
16
	local name="$1"
17
	local file="$2"
18
19
	echo -e "${BLUE}Benchmark: $name${NC}"
20
	echo "----------------------------------------"
21
22
	# 1. Parse + Compile Time (nix-irc)
23
	echo -n "  Parse + Compile: "
24
	local compile_output=$( (time "$IRC_BIN" "$file" /tmp/bench.nixir 2>&1) 2>&1)
25
	local compile_time=$(echo "$compile_output" | grep "real" | awk '{print $2}')
26
	echo -e "${GREEN}$compile_time${NC}"
27
28
	# 2. IR Size
29
	if [ -f /tmp/bench.nixir ]; then
30
		local ir_size=$(stat -f%z /tmp/bench.nixir 2>/dev/null || stat -c%s /tmp/bench.nixir 2>/dev/null)
31
		echo -e "  IR Bundle Size:  ${GREEN}${ir_size} bytes${NC}"
32
	fi
33
34
	# 3. Native Nix evaluation time
35
	echo -n "  Native Eval:     "
36
	local native_time=$( (time nix-instantiate --eval --strict "$file" >/dev/null 2>&1) 2>&1 | grep "real" | awk '{print $2}')
37
	echo -e "${GREEN}$native_time${NC}"
38
39
	# 4. With Plugin evaluation time
40
	echo -n "  Plugin Eval:     "
41
	local plugin_time=$( (time nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --strict "$file" >/dev/null 2>&1) 2>&1 | grep "real" | awk '{print $2}')
42
	echo -e "${GREEN}$plugin_time${NC}"
43
44
	echo ""
45
}
46
47
echo "# Running benchmarks..."
48
echo ""
49
50
run_benchmark "Simple Expressions" "$BENCH_DIR/simple.nix"
51
run_benchmark "Medium Complexity" "$BENCH_DIR/medium.nix"
52
run_benchmark "Large/Complex" "$BENCH_DIR/large.nix"
53
54
# File size comparison
55
echo -e "${BLUE}File Size Comparison${NC}"
56
echo "----------------------------------------"
57
testdir=$(mktemp -d)
58
59
for f in "$BENCH_DIR"/*.nix; do
60
	nixsize=$(stat -c%s "$f" 2>/dev/null || stat -f%z "$f" 2>/dev/null)
61
	base=$(basename "$f" .nix)
62
	irfile="${testdir}/${base}.nixir"
63
	$IRC_BIN "$f" "$irfile" >/dev/null 2>&1
64
	if [ -f "$irfile" ]; then
65
		irsize=$(stat -c%s "$irfile" 2>/dev/null || stat -f%z "$irfile" 2>/dev/null)
66
		ratio=$((irsize * 100 / nixsize))
67
		echo "  $base: ${nixsize}B => ${irsize}B (${ratio}% of source)"
68
	fi
69
done