diff options
| author | y-jan137 <yousefjan24000@gmail.com> | 2026-05-06 10:46:26 +0300 |
|---|---|---|
| committer | y-jan137 <yousefjan24000@gmail.com> | 2026-05-06 10:46:26 +0300 |
| commit | 5bd44b649bd706f9c29820c13c752f82ff276abe (patch) | |
| tree | 7af3197ec974355327c24c31d01f146c0ca66e5a /bench.sh | |
| parent | de3f8b33f53e72ebda59d1e2aca201eec8bea9e8 (diff) | |
Diffstat (limited to 'bench.sh')
| -rwxr-xr-x | bench.sh | 49 |
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" |