SPB Git

spb/metrika Public

Stata-class statistics, GPU-accelerated by Apple Silicon. Native Swift — no Electron, no Python runtime, no compromises.

Swift 92.4% HTML 3.3% R 3% Shell 1.3%
1.8 KB · 55 lines shellscript
Raw Blame History
1#!/bin/bash2#3#  bench.sh — Metrika4#5#  Author:  Simon-Pierre Boucher6#  Contact: contact@spboucher.ai7#  Copyright © 2026 Simon-Pierre Boucher. All rights reserved.8#9#  Performance benchmark harness (CLAUDE.md §8). Generates a synthetic10#  dataset and times the core pipeline through metrika-cli. CI compares11#  against the budget table; regressions >10% fail the build.12#13#  Usage: Tests/Bench/bench.sh [rows]   (default 1,000,000)14#15set -euo pipefail16export LC_ALL=C1718ROWS="${1:-1000000}"19ROOT="$(cd "$(dirname "$0")/../.." && pwd)"20DATA="$(mktemp -d)/bench.csv"21trap 'rm -rf "$(dirname "$DATA")"' EXIT2223echo "generating $ROWS rows…"24awk -v n="$ROWS" 'BEGIN {25  srand(42)26  print "revenue,price,region,firm_id"27  for (i = 1; i <= n; i++) {28    price = 5 + 15 * rand()29    region = (i % 3) + 130    revenue = exp(4 - 0.08 * price + 0.1 * region + 0.15 * (rand() - 0.5))31    printf "%.6f,%.4f,%d,%d\n", revenue, price, region, (i % 500) + 132  }33}' > "$DATA"3435cd "$ROOT/MetrikaKit"36swift build -c release --product metrika-cli >/dev/null37CLI=".build/release/metrika-cli"3839bench() { # bench <label> <command...>40  local label="$1"; shift41  local start end42  start=$(python3 -c 'import time; print(time.time())')43  "$CLI" "$@" >/dev/null44  end=$(python3 -c 'import time; print(time.time())')45  printf "%-28s %8.3f s\n" "$label" "$(echo "$end - $start" | bc)"46}4748bench "use csv ($ROWS rows)" -e "use $DATA"49bench "use + summarize"       -e "use $DATA" -e "summarize"50bench "use + reg (robust)"    -e "use $DATA" -e "gen log_rev = ln(revenue)" \51                              -e "reg log_rev price, robust"52bench "use + bootstrap(1000)" -e "use $DATA" -e "keep in 1/100000" \53                              -e "gen log_rev = ln(revenue)" \54                              -e "bootstrap, reps(1000) seed(42): reg log_rev price"55