SPB Git

Repository Public License

benchmark.sh 2.7 KB 51 lines shellscript

1#!/usr/bin/env bash2# ORIX Secure3# File: Scripts/benchmark.sh4# Description: Runs the engine packages' tests in a release build on the host Mac and collects the numbers the measurement5#              tests print (URL analysis timing, SHA-256 throughput, archive and folder scans, fingerprints, grouping, cache,6#              PDF rendering, live TLS / DNS / latency, X.509 fuzzing). Full output: build/benchmarks/<package>.txt.7#              usage: benchmark.sh [package …]        (default: every package that prints measurements)8#              Release objects go to build/bench-scratch/<package>, so the packages' default .build folders and9#              build/DerivedData are left alone. These are host-Mac figures: they say nothing about an iPhone.10#11# Author: Simon-Pierre Boucher12# Contact: contact@spboucher.ai13set -uo pipefail14cd "$(dirname "$0")/.."15ROOT="$PWD"16OUT="$ROOT/build/benchmarks"17SCRATCH="$ROOT/build/bench-scratch"18mkdir -p "$OUT" "$SCRATCH"1920# Packages whose test targets print measured numbers (grep -rn 'print(' Packages/*/Tests).21PACKAGES=("$@")22[[ ${#PACKAGES[@]} -eq 0 ]] && PACKAGES=(ORIXURLRisk ORIXFileInspection ORIXMediaCleanup ORIXNetworkLab ORIXReporting ORIXSecureEngines)2324# Lines written by the tests themselves (not by the test runner or the compiler).25MEASURED='^(TIMING|BENIGN CORPUS|SUSPICIOUS CORPUS|SHA-256 throughput|ZIP central directory|Inspection of|Large-file scan|Duplicate scan|PERFORMANCE|FINGERPRINT|GROUPING|CACHE|CANCELLATION|MEASURED|LIVE|NOTE|PDF 300|host probe|  +[a-zA-Z])'2627{28  echo "date: $(date '+%Y-%m-%d %H:%M:%S %z')"29  echo "host: $(sysctl -n hw.model) — $(sysctl -n machdep.cpu.brand_string), $(sysctl -n hw.ncpu) cores, $(( $(sysctl -n hw.memsize) / 1073741824 )) GB"30  echo "system: $(sw_vers -productName) $(sw_vers -productVersion) ($(sw_vers -buildVersion))"31  echo "xcode: $(xcodebuild -version 2>/dev/null | tr '\n' ' ')"32  echo "swift: $(swift --version 2>&1 | head -1)"33  echo "build: swift test -c release -Xswiftc -enable-testing"34} | tee "$OUT/host.txt"3536status=037for name in "${PACKAGES[@]}"; do38  package="$ROOT/Packages/$name"39  [[ -d "$package/Tests" ]] || { echo "== $name: no test target"; status=1; continue; }40  echo41  echo "== $name"42  # -enable-testing keeps `@testable import` working in an optimized build.43  (cd "$package" && swift test -c release -Xswiftc -enable-testing --scratch-path "$SCRATCH/$name" 2>&1) > "$OUT/$name.txt"44  code=$?45  clean=$(sed -E 's/\x1b\[[0-9;]*m//g' "$OUT/$name.txt")46  echo "$clean" | grep -E "$MEASURED" | cut -c1-60047  echo "$clean" | grep -E "Test run with|error:|✘" | cut -c1-30048  [[ $code -eq 0 ]] || { echo "$name: swift test exited with $code (see build/benchmarks/$name.txt)"; status=1; }49done50exit $status51
Files main
Menu

Theme