Repository navigation
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·77 lines (65 loc) · 2.81 KB
/
Copy pathbenchmark.sh
File metadata and controls
executable file
·77 lines (65 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# Benchmark formwatch against the bundled demo site.
#
# scripts/benchmark.sh # 5 timed runs, default port/wait
# RUNS=10 WAIT=0 PORT=9001 scripts/benchmark.sh
# MAX_CONCURRENT=1 scripts/benchmark.sh # sweep concurrency
# NO_SCREENSHOTS=1 scripts/benchmark.sh # isolate screenshot cost
#
# Starts `formwatch demo` on localhost, then repeatedly runs `monitor` over
# every demo form and reports wall-clock timings. Everything is local, so
# the numbers reflect formwatch's own overhead (browser launch, checks,
# report writing) plus the `--wait` you set — not network latency. It never
# touches a third-party site, so it's safe to run anywhere.
set -euo pipefail
cd "$(dirname "$0")/.."
PORT="${PORT:-8099}"
RUNS="${RUNS:-5}"
WAIT="${WAIT:-1}"
MAX_CONCURRENT="${MAX_CONCURRENT:-4}"
NO_SCREENSHOTS="${NO_SCREENSHOTS:-0}"
ADDR="127.0.0.1:${PORT}"
BIN="./target/release/formwatch"
HIST="$(mktemp -d)/history"
SCREENSHOT_FLAG=()
if [ "$NO_SCREENSHOTS" = "1" ]; then
SCREENSHOT_FLAG=(--no-screenshots)
fi
echo "building release binary…" >&2
cargo build --release -q
"$BIN" demo --addr "$ADDR" >/dev/null 2>&1 &
SRV=$!
trap 'kill "$SRV" 2>/dev/null || true' EXIT
for _ in $(seq 1 50); do
curl -sf -o /dev/null "http://${ADDR}/good-form.html" && break
sleep 0.2
done
run_once() {
"$BIN" --history-dir "$HIST" monitor demo-sites/forms.yml \
--wait "$WAIT" --max-concurrent "$MAX_CONCURRENT" "${SCREENSHOT_FLAG[@]}" --json \
>/tmp/formwatch-bench.json 2>/dev/null || true
}
run_once # warm-up (Chrome launch, page cache)
times=()
for _ in $(seq 1 "$RUNS"); do
start=$(date +%s.%N)
run_once
end=$(date +%s.%N)
times+=("$(awk -v a="$start" -v b="$end" 'BEGIN { printf "%.2f", b - a }')")
done
forms=$(grep -o '"url"' /tmp/formwatch-bench.json | wc -l | tr -d ' ')
checks=$(grep -o '"status"' /tmp/formwatch-bench.json | wc -l | tr -d ' ')
printf '%s\n' "${times[@]}" | sort -n >/tmp/formwatch-bench-times
min=$(head -1 /tmp/formwatch-bench-times)
max=$(tail -1 /tmp/formwatch-bench-times)
median=$(awk -v n="$RUNS" 'NR == int((n + 1) / 2) { print; exit }' /tmp/formwatch-bench-times)
forms_per_min=$(awk -v f="$forms" -v m="$median" 'BEGIN { printf "%.1f", (f / m) * 60 }')
checks_per_sec=$(awk -v c="$checks" -v m="$median" 'BEGIN { printf "%.1f", c / m }')
screenshots_label="on"
if [ "$NO_SCREENSHOTS" = "1" ]; then
screenshots_label="off"
fi
echo
echo "| Forms | Checks/run | Runs | Wait | Concurrency | Screenshots | min (s) | median (s) | max (s) | forms/min | checks/s |"
echo "|------:|-----------:|-----:|-----:|------------:|:------------|--------:|-----------:|--------:|----------:|---------:|"
echo "| $forms | $checks | $RUNS | ${WAIT}s | $MAX_CONCURRENT | $screenshots_label | $min | $median | $max | $forms_per_min | $checks_per_sec |"