Repository Public
1#!/bin/bash2# Measures NEXTERM on this machine and prints a Markdown table for docs/PERFORMANCE.md.3# Metrics: cold launch to first window, memory/CPU with N sessions (1,4,8,16,32), sustained output throughput,4# idle CPU, workspace restoration time. Uses an isolated data dir. Requires Accessibility for System Events.5set -euo pipefail6cd "$(dirname "$0")/.."7APP="${1:-build/DerivedData/Build/Products/Release/NEXTERM.app}"8[ -d "$APP" ] || APP=build/DerivedData/Build/Products/Debug/NEXTERM.app9BIN="$APP/Contents/MacOS/NEXTERM"10DATA=$(mktemp -d /tmp/nexterm-perf.XXXX)11now_ms() { python3 -c 'import time; print(int(time.time()*1000))'; }12WINPROBE=/tmp/nexterm-winprobe13if [ ! -x "$WINPROBE" ]; then # compiled once: swift scripts take ~1 s to start, too slow to poll with14 cat > /tmp/nexterm-winprobe.swift <<'SW'15import CoreGraphics16let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []17exit(list.contains { ($0["kCGWindowOwnerName"] as? String) == "NEXTERM" && ($0["kCGWindowLayer"] as? Int) == 0 } ? 0 : 1)18SW19 swiftc -O -o "$WINPROBE" /tmp/nexterm-winprobe.swift 2>/dev/null20fi21first_window_ms() { # poll until an on-screen NEXTERM window exists22 local t0=$1; for i in $(seq 1 600); do23 if "$WINPROBE"; then echo $(( $(now_ms) - t0 )); return; fi; sleep 0.02; done; echo "timeout"; }24mem_mb() { ps -o rss= -p "$1" | awk '{printf "%.0f", $1/1024}'; }25cpu_pct() { ps -o %cpu= -p "$1" | tr -d ' '; }26echo "| Metric | Value | Notes |"; echo "|---|---|---|"27echo "| Hardware | $(sysctl -n machdep.cpu.brand_string), $(sysctl -n hw.ncpu) cores, $(( $(sysctl -n hw.memsize)/1073741824 )) GB | $(sw_vers -productName) $(sw_vers -productVersion) |"28echo "| Build | $(basename "$(dirname "$APP")") configuration | NEXTERM $(defaults read "$PWD/$APP/Contents/Info" CFBundleShortVersionString) |"2930pkill -x NEXTERM 2>/dev/null || true; sleep 131# warm the file cache once, then measure cold-ish launch (app binary cached, fresh data dir)32T0=$(now_ms); open -n "$APP" --args -NEXTERMDataDir "$DATA" -NEXTERMFreshWorkspace 133LAUNCH=$(first_window_ms "$T0"); PID=$(pgrep -x NEXTERM | head -1); sleep 234echo "| Launch → first window | ${LAUNCH} ms | fresh workspace, 1 shell |"35echo "| Memory, 1 session | $(mem_mb $PID) MB RSS | after 2 s |"36sleep 5; echo "| Idle CPU, 1 session | $(cpu_pct $PID) % | ps %cpu after 5 s idle |"3738osascript -e 'tell application "NEXTERM" to activate' >/dev/null; sleep 0.539count=140for target in 4 8 16 32; do41 while [ $count -lt $target ]; do42 item="Split Right"; [ $((count % 2)) -eq 0 ] && item="Split Down"43 osascript -e "tell application \"System Events\" to tell process \"NEXTERM\" to click menu item \"$item\" of menu \"Shell\" of menu bar 1" >/dev/null44 count=$((count+1)); sleep 0.2545 done46 sleep 347 live=$(pgrep -P $PID | wc -l | tr -d ' ')48 echo "| Memory, $target sessions | $(mem_mb $PID) MB RSS | $live child shells alive; idle CPU $(cpu_pct $PID) % |"49done5051# Throughput: 200 MB of text through one pane. The command lives in a helper script because System52# Events cannot type '|' or '>' on every keyboard layout.53cat > "$DATA/burst.sh" <<'SH'54s=$(date +%s.%N); yes abcdefghijklmnopqrstuvwxyz0123456789 | head -c 200000000; e=$(date +%s.%N)55echo "THROUGHPUT $(echo "200/($e-$s)" | bc -l)" > "$(dirname "$0")/tp.txt"56SH57osascript -e 'tell application "System Events" to tell process "NEXTERM" to click menu item "Maximize / Restore Pane" of menu "Pane" of menu bar 1' >/dev/null58osascript -e "tell application \"System Events\" to tell process \"NEXTERM\" to keystroke \"sh $DATA/burst.sh\" & return" >/dev/null59for i in $(seq 1 120); do [ -f "$DATA/tp.txt" ] && break; sleep 1; done60sleep 1; echo "| Sustained output | $(cat "$DATA/tp.txt" 2>/dev/null | awk '{printf "%.0f MB/s", $2}') | 200 MB via \`yes | head -c\`, 32 panes open, CPU during burst $(cpu_pct $PID) % |"61sleep 3; echo "| Idle CPU, 32 sessions | $(cpu_pct $PID) % | after burst settled |"6263# Restoration: quit (saves) and relaunch; measure to first window + until 32 shells are back.64osascript -e 'tell application "NEXTERM" to quit' >/dev/null; sleep 265T0=$(now_ms); open -n "$APP" --args -NEXTERMDataDir "$DATA"66R1=$(first_window_ms "$T0"); PID=$(pgrep -x NEXTERM | head -1)67for i in $(seq 1 200); do [ "$(pgrep -P $PID | wc -l | tr -d ' ')" -ge 32 ] && break; sleep 0.05; done68R2=$(( $(now_ms) - T0 ))69echo "| Restore 32-pane workspace | window ${R1} ms, all 32 shells ${R2} ms | layout restored, new processes |"70sleep 2; echo "| Memory after restore | $(mem_mb $PID) MB RSS | 32 sessions |"71osascript -e 'tell application "NEXTERM" to quit' >/dev/null 2>&1 || true72echo; echo "data dir: $DATA"73