tests/benchmark: fine-grain timing reports

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ia481b0129193540636665340bd257d136a6a6964
This commit is contained in:
raf 2026-02-22 23:47:41 +03:00
commit 347175bb86
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -32,8 +32,8 @@ run_benchmark() {
echo -e "${BLUE}=== $name ===${NC}" echo -e "${BLUE}=== $name ===${NC}"
echo "" echo ""
# Measure compilation time # Measure compilation time only
echo -n " Compilation time: " echo -n " Compilation only: "
local compile_start local compile_start
compile_start=$(date +%s%N) compile_start=$(date +%s%N)
"$IRC_BIN" "$file" /tmp/bench.nixir >/dev/null 2>&1 "$IRC_BIN" "$file" /tmp/bench.nixir >/dev/null 2>&1
@ -42,6 +42,42 @@ run_benchmark() {
local compile_ms=$(((compile_end - compile_start) / 1000000)) local compile_ms=$(((compile_end - compile_start) / 1000000))
echo -e "${YELLOW}${compile_ms}ms${NC}" echo -e "${YELLOW}${compile_ms}ms${NC}"
# Measure IR loading only (deserialization + evaluation)
echo -n " IR load only: "
PLUGIN_PATH="$(pwd)/build/nix-ir-plugin.so"
if [ ! -f "$PLUGIN_PATH" ]; then
echo -e "${YELLOW}skipped${NC} (plugin not built)"
else
# Pre-compile the IR
"$IRC_BIN" "$file" /tmp/bench.nixir >/dev/null 2>&1
# Measure just the loading (average of 10 runs to reduce noise)
local total_load_us=0
for _ in {1..10}; do
local load_output
load_output=$(nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --expr "builtins.nixIR_loadIR \"/tmp/bench.nixir\"" 2>&1 >/dev/null | grep "nixIR timing" | grep -oP 'total=\K[0-9]+')
total_load_us=$((total_load_us + load_output))
done
local avg_load_us=$((total_load_us / 10))
local avg_load_ms_frac=$(awk "BEGIN {printf \"%.3f\", $avg_load_us / 1000}")
echo -e "${GREEN}${avg_load_ms_frac}ms${NC} avg (10 runs)"
fi
# Measure full pipeline (compile + nix-instantiate overhead + IR load)
echo -n " Full pipeline: "
if [ ! -f "$PLUGIN_PATH" ]; then
echo -e "${YELLOW}skipped${NC}"
else
local pipeline_start
pipeline_start=$(date +%s%N)
"$IRC_BIN" "$file" /tmp/bench.nixir >/dev/null 2>&1
nix-instantiate --plugin-files "$PLUGIN_PATH" --eval --expr "builtins.nixIR_loadIR \"/tmp/bench.nixir\"" >/dev/null 2>&1
local pipeline_end
pipeline_end=$(date +%s%N)
local pipeline_ms=$(((pipeline_end - pipeline_start) / 1000000))
echo -e "${YELLOW}${pipeline_ms}ms${NC}"
fi
# Source and IR sizes # Source and IR sizes
local src_size local src_size
src_size=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null) src_size=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null)