aboutsummaryrefslogtreecommitdiff
path: root/bench.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bench.sh')
-rwxr-xr-xbench.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/bench.sh b/bench.sh
new file mode 100755
index 0000000..049b035
--- /dev/null
+++ b/bench.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+set -euo pipefail
+
+BIN=".build/release/pixel-sort"
+INPUT="examples/input-1920x1080.png"
+OUTPUT="/tmp/pixel-sort-bench-output.png"
+ITERS="${1:-100}"
+
+echo "Binary: $BIN"
+echo "Input: $INPUT"
+echo "Iterations: $ITERS"
+echo ""
+
+# Warmup
+"$BIN" "$INPUT" "$OUTPUT" >/dev/null 2>&1
+
+times=()
+for i in $(seq 1 "$ITERS"); do
+ t=$( { /usr/bin/time -p "$BIN" "$INPUT" "$OUTPUT" ; } 2>&1 | awk '/^real/ {print $2}')
+ times+=("$t")
+done
+
+# Sort and compute stats
+sorted=($(printf '%s\n' "${times[@]}" | sort -n))
+n=${#sorted[@]}
+min=${sorted[0]}
+max=${sorted[$((n-1))]}
+median=${sorted[$((n/2))]}
+p95=${sorted[$(( (n * 95) / 100 ))]}
+p99=${sorted[$(( (n * 99) / 100 ))]}
+
+sum=$(printf '%s\n' "${times[@]}" | awk '{s+=$1} END {print s}')
+mean=$(echo "$sum $n" | awk '{printf "%.4f", $1/$2}')
+
+echo "=== Results (1920x1080, ${ITERS} runs) ==="
+echo " Min: ${min}s"
+echo " Mean: ${mean}s"
+echo " Median: ${median}s"
+echo " P95: ${p95}s"
+echo " P99: ${p99}s"
+echo " Max: ${max}s"
+echo ""
+echo " Target: ≤0.002s (2ms) P95"
+
+p95_ms=$(echo "$p95" | awk '{printf "%.1f", $1 * 1000}')
+pass=$(echo "$p95" | awk '{print ($1 <= 0.002) ? "PASS" : "FAIL"}')
+echo " P95 = ${p95_ms}ms → ${pass}"
+
+rm -f "$OUTPUT"