Repository Public
1#!/bin/bash2# Measures launch time and memory of a built SP Term on this machine.3# Scripts/bench.sh [path/to/SP Term.app]4# Launch time = from `open` until the first window is on screen (polled every 10 ms through the5# window server), 5 launches after one warm-up. Memory = physical footprint reported by `footprint`6# and resident size from `ps`, with 1 pane and after opening the 8-pane preset.7set -uo pipefail8cd "$(dirname "$0")/.."9APP="${1:-dist/SP Term.app}"10DATA="/tmp/spterm-bench-data"11cat > /tmp/spterm-waitwin.swift <<'S'12import CoreGraphics13import Foundation14let start = DispatchTime.now().uptimeNanoseconds15let p = Process(); p.executableURL = URL(fileURLWithPath: "/usr/bin/open"); p.arguments = Array(CommandLine.arguments.dropFirst())16try! p.run()17while true {18 let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []19 if list.contains(where: { ($0["kCGWindowOwnerName"] as? String) == "SP Term" && ($0["kCGWindowLayer"] as? Int) == 0 }) { break }20 if DispatchTime.now().uptimeNanoseconds - start > 20_000_000_000 { print("timeout"); exit(1) }21 usleep(10_000)22}23print(String(format: "%.0f", Double(DispatchTime.now().uptimeNanoseconds - start) / 1_000_000))24S25swiftc -O -o /tmp/spterm-waitwin /tmp/spterm-waitwin.swift 2>/dev/null || { echo "cannot compile the timing helper"; exit 1; }26quit() { osascript -e 'tell application "SP Term" to quit' >/dev/null 2>&1; local i=0; while pgrep -x "SP Term" >/dev/null && [ $i -lt 50 ]; do sleep 0.1; i=$((i+1)); done; pkill -x "SP Term" 2>/dev/null; sleep 0.4; }27mem() { local pid; pid="$(pgrep -x "SP Term" | head -1)"; echo "footprint=$(footprint "$pid" 2>/dev/null | sed -n 's/.*Footprint: \([0-9.]* [KMG]B\).*/\1/p' | head -1) rss=$(( $(ps -o rss= -p "$pid") / 1024 ))MB"; }2829echo "machine: $(sysctl -n machdep.cpu.brand_string), $(( $(sysctl -n hw.memsize) / 1073741824 )) GB, macOS $(sw_vers -productVersion)"30echo "app: $APP ($(lipo -archs "$APP/Contents/MacOS/SP Term"))"31quit; rm -rf "$DATA"32/tmp/spterm-waitwin "$APP" --args -SPTermDataDir "$DATA" -SPTermFresh 1 >/dev/null; sleep 1; quit33times=()34for i in 1 2 3 4 5; do35 t="$(/tmp/spterm-waitwin "$APP" --args -SPTermDataDir "$DATA" -SPTermFresh 1)"; times+=("$t"); sleep 1.2; quit36done37echo "launch_to_first_window_ms: ${times[*]} (median $(printf '%s\n' "${times[@]}" | sort -n | sed -n 3p))"38/tmp/spterm-waitwin "$APP" --args -SPTermDataDir "$DATA" -SPTermFresh 1 >/dev/null; sleep 439echo "memory_1_pane_idle: $(mem)"40quit41/tmp/spterm-waitwin "$APP" --args -SPTermDataDir "$DATA" -SPTermFresh 1 -SPTermPreset grid8 >/dev/null; sleep 642echo "memory_8_panes_idle: $(mem) shells: $(pgrep -P "$(pgrep -x "SP Term" | head -1)" | wc -l | tr -d ' ')"43echo "cpu_idle_8_panes: $(ps -o %cpu= -p "$(pgrep -x "SP Term" | head -1)" | tr -d ' ')%"44quit45