#!/usr/bin/env bash # Time full extraction with Peel's engine against macOS's own tools, on fixtures # built here (nothing downloaded). Prints a Markdown table for docs/competitive.md. # # Usage: scripts/bench.sh [runs] (default 3; the table shows the median) # The tools are interleaved: each run times Peel, ditto, bsdtar and unar # once, rotating which goes first, after one untimed round (see Timing). # Env: PEEL=/path/to/peel (default: dist/Peel.app's engine, else target/release/peel) # BENCH_DIR=/path (default: a temp dir, removed afterwards) # # Baselines: `ditto -x -k` is the engine behind Archive Utility for ZIP; `tar -xf` # is macOS's bsdtar; `unar` is The Unarchiver's command-line engine, timed only when # it is installed (otherwise its column says "not installed", never a number). Peel's browse-on-open does the same extraction into its # browse folder, so "extract" is also Peel's time from double-click to a folder # Finder can show (Finder's own redraw not included). FSKit mounts aren't timed: # the module doesn't mount on this macOS yet (#41). set -euo pipefail RUNS="${1:-3}" 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 (scripts/build-app.sh or cargo build --release)" >&2; exit 1; } OWN_DIR=0 if [[ -z "${BENCH_DIR:-}" ]]; then BENCH_DIR="$(mktemp -d)"; OWN_DIR=1; fi FIX="$BENCH_DIR/fixtures"; OUT="$BENCH_DIR/out" cleanup() { rm -rf "$OUT" "$BENCH_DIR/time.txt"; if [[ "$OWN_DIR" == 1 ]]; then rm -rf "$BENCH_DIR"; fi; } trap cleanup EXIT mkdir -p "$FIX" # ── Fixtures ──────────────────────────────────────────────────────────────── src() { mkdir -p "$FIX/src-$1"; echo "$FIX/src-$1"; } if [[ ! -f "$FIX/.built" ]]; then echo "Building fixtures in ${FIX}…" >&2 # Text-like data compresses the way real documents do; random data doesn't. python3 - "$FIX" <<'PY' import os, random, sys fix = sys.argv[1] rnd = random.Random(42) words = [w.strip() for w in "lorem ipsum dolor sit amet archive folder finder peel open inside zip tar".split()] def text(n): return (" ".join(rnd.choice(words) for _ in range(n // 6)) + "\n").encode()[:n] def tree(name, files, size, binary=False): d = os.path.join(fix, "src-" + name) os.makedirs(d, exist_ok=True) for i in range(files): sub = os.path.join(d, f"d{i % 50:02d}") os.makedirs(sub, exist_ok=True) with open(os.path.join(sub, f"f{i:05d}.txt"), "wb") as f: f.write(os.urandom(size) if binary else text(size)) tree("small", 20, 4_000) # 20 files, ~80 KB tree("many", 20_000, 1_000) # 20,000 files, ~20 MB tree("large", 4, 64_000_000) # 4 files, ~256 MB of text tree("binary", 2, 64_000_000, True) # 2 files, 128 MB incompressible PY for n in small many large binary; do "$PEEL" create -q "$FIX/$n.zip" "$FIX/src-$n"; done PEEL_PASSWORD=bench "$PEEL" create -q "$FIX/encrypted.zip" "$FIX/src-large" "$PEEL" create -q "$FIX/many.tar.gz" "$FIX/src-many" "$PEEL" create -q "$FIX/large.tar.gz" "$FIX/src-large" # The four RAR volumes are test fixtures in the Peel repository; without them (a copy of # this script run elsewhere) the RAR row is skipped, not faked. for i in 1 2 3 4; do cp "$ROOT/crates/peel-core/tests/fixtures/multipart/multivolume.part$i.rar" "$FIX/" 2>/dev/null || true done rm -rf "$FIX"/src-* touch "$FIX/.built" fi # ── Timing ────────────────────────────────────────────────────────────────── # The tools take turns: each run times every tool once, starting with a # different tool each time, after one untimed round. Timing each tool's runs as # a block made the first tool in a row (Peel) pay for the machine settling: on a # Mac under memory pressure the first few 256 MB extractions of a row took about # 0.2 s longer whichever tool ran them. /usr/bin/time measures only the command # (a timer process started inside the timed span added its own startup). export PEEL_PASSWORD=bench TF="$BENCH_DIR/time.txt" UNAR="$(command -v unar || true)" median() { sort -n | awk '{a[NR]=$1} END {print a[int((NR+1)/2)]}'; } # run_one : extracts $a once with that tool into a fresh OUT; prints seconds, or n/a. run_one() { local cmd case "$1" in peel) cmd=("$PEEL" x "$FIX/$a" -o "$OUT" -q) ;; ditto) cmd=(/usr/bin/ditto -x -k "$FIX/$a" "$OUT") ;; tar) cmd=(/usr/bin/tar -xf "$FIX/$a" -C "$OUT") [[ "$a" == encrypted.zip ]] && cmd=(/usr/bin/tar --passphrase bench -xf "$FIX/$a" -C "$OUT") ;; unar) cmd=("$UNAR" -q -D -f -o "$OUT" "$FIX/$a") [[ "$a" == encrypted.zip ]] && cmd=("$UNAR" -q -D -f -p bench -o "$OUT" "$FIX/$a") ;; esac rm -rf "$OUT"; mkdir -p "$OUT" /usr/bin/time -p -o "$TF" "${cmd[@]}" >/dev/null 2>&1 || { echo "n/a"; return; } awk '/^real/ {print $2}' "$TF" } # summary : the median, or n/a if any run failed. summary() { case " $* " in *" n/a "*) echo "n/a" ;; *) printf '%s\n' "$@" | median ;; esac } size() { du -sh "$FIX/$1" 2>/dev/null | awk '{print $1}'; } echo "| Archive | Size | Peel | Archive Utility engine (\`ditto -x -k\`) | bsdtar (\`tar -xf\`) | The Unarchiver engine (\`unar\`) |" echo "| --- | --- | --- | --- | --- | --- |" for a in small.zip many.zip large.zip binary.zip encrypted.zip many.tar.gz large.tar.gz multivolume.part1.rar; do [[ "$a" == *.rar && ! -f "$FIX/$a" ]] && continue case "$a" in encrypted.zip | *.tar.gz | *.rar) tools=(peel tar) ;; *) tools=(peel ditto tar) ;; esac [[ -n "$UNAR" ]] && tools+=(unar) peel_runs=(); ditto_runs=(); tar_runs=(); unar_runs=() for run in $(seq 0 "$RUNS"); do # run 0 is the untimed round k=$((run % ${#tools[@]})) for t in "${tools[@]:k}" "${tools[@]:0:k}"; do s=$(run_one "$t") [[ "$run" == 0 ]] && continue case "$t" in peel) peel_runs+=("$s") ;; ditto) ditto_runs+=("$s") ;; tar) tar_runs+=("$s") ;; unar) unar_runs+=("$s") ;; esac done done peel_t=$(summary "${peel_runs[@]}"); tar_t=$(summary "${tar_runs[@]}") unar_t="not installed"; [[ -n "$UNAR" ]] && unar_t=$(summary "${unar_runs[@]}") case "$a" in encrypted.zip) ditto_t="can't (AES)" ;; *.zip) ditto_t=$(summary "${ditto_runs[@]}") ;; *.tar.gz) ditto_t="—" ;; *.rar) ditto_t="can't" ;; esac name="$a"; [[ "$a" == multivolume.part1.rar ]] && name="multivolume RAR (4 parts)" sz=$(size "$a"); [[ "$a" == *.rar ]] && sz="$(du -ch "$FIX"/multivolume.part*.rar | tail -1 | awk '{print $1}')" echo "| $name | $sz | ${peel_t} s | ${ditto_t}$([[ "$ditto_t" =~ ^[0-9] ]] && echo " s") | ${tar_t}$([[ "$tar_t" =~ ^[0-9] ]] && echo " s") | ${unar_t}$([[ "$unar_t" =~ ^[0-9] ]] && echo " s") |" done 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$([[ -n "$UNAR" ]] && echo ", unar $("$UNAR" -v)")._"