#!/usr/bin/env bash # Time listing archives of 25,000 and 250,000 entries, flat and nested, with # Peel's CLI, the engine call the app makes, and the system tools. Archives are # generated here from fixed rules (nothing downloaded). Prints Markdown tables. # Used by scripts/perf-gate.sh for the listing gate (#799, alongside #707). # # Usage: scripts/bench-list.sh [runs] (default 5; the tables show the median) # Each run times every tool once, rotating which goes first, after one # untimed round (the method of scripts/bench.sh). # Env: PEEL=/path/to/peel (default: dist/Peel.app's engine, else target/release/peel) # BENCH_DIR=/path (default /private/tmp/peel-bench-list; archives are kept # there between runs, never inside the repository) # BENCH_FFI=0 (skip the engine call, which needs a cargo test build) # # Tables: # CLI `peel list` against `bsdtar -tf` (libarchive), `zipinfo -1` (ZIP only) and # `7zz l` and `lsar` (The Unarchiver's lister) when installed (otherwise the # column says so, never a number). # Output goes to /dev/null: this is time to produce the full listing. # Engine `peel_list_limited_with_password` in peel-ffi, the function the app's # listing calls through its XPC service, timed by an ignored test # (list_timing): with the app's cap of 5,000 entries and with no cap. # The JSON the app parses is built inside the timed call. # # A failed Peel row, or a listing whose entry count differs from the archive's, # prints FAIL and exits 1. Never prints a number it did not measure. # # Archives (rows): flat = N files in one folder; nested = N files in a three-level # tree of folders (10 files per folder, with an entry for each folder), the way Finder zips a project. # Each file holds 64 bytes. ZIP and tar are both generated, deflated/uncompressed. set -euo pipefail RUNS="${1:-5}" ROOT="$(cd "$(dirname "$0")/.." && pwd)" PEEL="${PEEL:-}" if [[ -z "$PEEL" ]]; then for c in "$ROOT/dist/Peel.app/Contents/Resources/peel" "$ROOT/target/release/peel"; do [[ -x "$c" ]] && PEEL="$c" && break done fi [[ -x "${PEEL:-}" ]] || { echo "No peel engine; build first (cargo build --release -p peel-cli) or set PEEL=" >&2; exit 2; } BENCH_DIR="${BENCH_DIR:-/private/tmp/peel-bench-list}" TF="$BENCH_DIR/time.txt" mkdir -p "$BENCH_DIR" trap 'rm -f "$TF"' EXIT SEVENZ="$(command -v 7zz || command -v 7z || true)" LSAR="$(command -v lsar || true)" # ── Archives ──────────────────────────────────────────────────────────────── # nameentries: the entry count includes folder entries in nested archives. MARK="$BENCH_DIR/.built-v1" if [[ ! -f "$MARK" ]]; then echo "Building archives in ${BENCH_DIR}…" >&2 python3 - "$BENCH_DIR" <<'PY' import io, sys, tarfile, zipfile out = sys.argv[1] body = b"x" * 64 def names(n, nested): files, dirs = [], [] if nested: # 10 files per leaf folder; leaf L is proj/a(L//2500)/b((L%2500)//50)/c(L%50). seen = {"proj/"} dirs.append("proj/") for i in range(n): leaf = i // 10 a, b, c = leaf // 2500, (leaf % 2500) // 50, leaf % 50 parts = [f"proj/a{a:02d}", f"proj/a{a:02d}/b{b:02d}", f"proj/a{a:02d}/b{b:02d}/c{c:02d}"] for d in parts: if d + "/" not in seen: seen.add(d + "/"); dirs.append(d + "/") files.append(f"{parts[2]}/f{i:06d}.txt") else: files = [f"flat/f{i:06d}.txt" for i in range(n)] dirs = ["flat/"] return dirs, files rows = [] for n in (25_000, 250_000): for nested in (False, True): dirs, files = names(n, nested) tag = f"{'nested' if nested else 'flat'}-{n // 1000}k" with zipfile.ZipFile(f"{out}/{tag}.zip", "w", zipfile.ZIP_DEFLATED) as z: for d in dirs: zi = zipfile.ZipInfo(d, (2026, 1, 1, 0, 0, 0)); zi.external_attr = (0o40755 << 16) | 0x10 z.writestr(zi, b"") for f in files: zi = zipfile.ZipInfo(f, (2026, 1, 1, 0, 0, 0)); zi.external_attr = 0o100644 << 16 zi.compress_type = zipfile.ZIP_DEFLATED z.writestr(zi, body) with tarfile.open(f"{out}/{tag}.tar", "w") as t: for d in dirs: ti = tarfile.TarInfo(d.rstrip("/")); ti.type = tarfile.DIRTYPE; ti.mode = 0o755; ti.mtime = 1767225600 t.addfile(ti) for f in files: ti = tarfile.TarInfo(f); ti.size = len(body); ti.mode = 0o644; ti.mtime = 1767225600 t.addfile(ti, io.BytesIO(body)) rows.append((tag, len(dirs) + len(files))) with open(f"{out}/counts.tsv", "w") as f: for tag, c in rows: f.write(f"{tag}\t{c}\n") PY touch "$MARK" fi ARCHIVES=() while IFS=$'\t' read -r tag count; do for ext in zip tar; do ARCHIVES+=("$tag.$ext:$count"); done done < "$BENCH_DIR/counts.tsv" # ── Timing ────────────────────────────────────────────────────────────────── median() { sort -n | awk '{a[NR]=$1} END {print a[int((NR+1)/2)]}'; } run_one() { # run_one : lists $a once with that tool; prints seconds, or n/a. local cmd case "$1" in peel) cmd=("$PEEL" ls "$BENCH_DIR/$a") ;; bsdtar) cmd=(/usr/bin/bsdtar -tf "$BENCH_DIR/$a") ;; zipinfo) cmd=(/usr/bin/zipinfo -1 "$BENCH_DIR/$a") ;; 7z) cmd=("$SEVENZ" l "$BENCH_DIR/$a") ;; lsar) cmd=("$LSAR" "$BENCH_DIR/$a") ;; esac /usr/bin/time -p -o "$TF" "${cmd[@]}" >/dev/null 2>&1 || { echo "n/a"; return; } awk '/^real/ {print $2}' "$TF" } summary() { case " $* " in *" n/a "*) echo "FAIL" ;; *) printf '%s\n' "$@" | median ;; esac; } cell() { case "$1" in FAIL|"—"*|"not installed") echo "$1" ;; *) echo "$1 s" ;; esac; } fail=0 echo "CLI: time to list every entry (output to /dev/null)" echo echo "| Archive | Entries | Peel (\`peel list\`) | bsdtar (\`tar -tf\`) | \`zipinfo -1\` | 7-Zip (\`7zz l\`) | Count | The Unarchiver (\`lsar\`) |" echo "| --- | --- | --- | --- | --- | --- | --- | --- |" for ac in "${ARCHIVES[@]}"; do a="${ac%%:*}"; count="${ac##*:}" tools=(peel bsdtar) [[ "$a" == *.zip ]] && tools+=(zipinfo) [[ -n "$SEVENZ" ]] && tools+=(7z) [[ -n "$LSAR" ]] && tools+=(lsar) runs=(); for t in "${tools[@]}"; do runs+=(""); done for run in $(seq 0 "$RUNS"); do # run 0 is the untimed round k=$((run % ${#tools[@]})) for off in $(seq 0 $((${#tools[@]} - 1))); do i=$(((k + off) % ${#tools[@]})) s=$(run_one "${tools[$i]}") [[ "$run" == 0 ]] && continue runs[$i]+="$s " done done peel_t="—"; bsd_t="—"; zi_t="—"; sz_t="not installed"; ls_t="not installed" for i in "${!tools[@]}"; do m=$(summary ${runs[$i]}) case "${tools[$i]}" in peel) peel_t="$m" ;; bsdtar) bsd_t="$m" ;; zipinfo) zi_t="$m" ;; 7z) sz_t="$m" ;; lsar) ls_t="$m" ;; esac done # Peel's entry count must be the archive's (the CLI prints one line per entry). got=$("$PEEL" ls "$BENCH_DIR/$a" 2>/dev/null | wc -l | tr -d ' ') verdict="ok" if [[ "$got" != "$count" ]]; then verdict="FAIL ($got of $count)"; fail=1; fi [[ "$peel_t" == FAIL ]] && fail=1 [[ "$a" == *.tar ]] && zi_t="—" echo "| $a | $count | $(cell "$peel_t") | $(cell "$bsd_t") | $(cell "$zi_t") | $(cell "$sz_t") | $verdict | $(cell "$ls_t") |" done if [[ "${BENCH_FFI:-1}" == 1 ]]; then echo echo "Engine: \`peel_list_limited_with_password\` (the app's listing call), JSON built inside the call" echo : > "$BENCH_DIR/ffi.tsv" for ac in "${ARCHIVES[@]}"; do printf '%s\t%s\n' "${ac##*:}" "$BENCH_DIR/${ac%%:*}" >> "$BENCH_DIR/ffi.tsv"; done ffi_log="$BENCH_DIR/ffi.log" if (cd "$ROOT" && PEEL_LIST_BENCH_FILE="$BENCH_DIR/ffi.tsv" PEEL_LIST_BENCH_RUNS="$RUNS" \ cargo test --release -q -p peel-ffi list_timing -- --ignored --nocapture --test-threads=1) > "$ffi_log" 2>&1; then echo "| Archive | Entries | App cap (5,000) | No cap |" echo "| --- | --- | --- | --- |" for ac in "${ARCHIVES[@]}"; do a="${ac%%:*}"; count="${ac##*:}" capped=$(awk -F'\t' -v p="$BENCH_DIR/$a" '$1=="list-ffi" && $2==p && $3=="cap 5000" {print $4}' "$ffi_log") full=$(awk -F'\t' -v p="$BENCH_DIR/$a" '$1=="list-ffi" && $2==p && $3=="cap 0" {print $4}' "$ffi_log") [[ -n "$capped" && -n "$full" ]] || { capped="FAIL"; full="FAIL"; fail=1; } echo "| $a | $count | $capped | $full |" done else echo "FAIL: the engine timing test failed:"; tail -20 "$ffi_log"; fail=1 fi fi echo echo "_$(sysctl -n machdep.cpu.brand_string), $(sysctl -n hw.ncpu) cores, macOS $(sw_vers -productVersion), median of $RUNS interleaved runs, $(date +%Y-%m-%d), load average $(sysctl -n vm.loadavg | tr -d '{}' | awk '{print $1}') at the end._" exit "$fail"