#!/bin/sh
# VsMacs benchmark: measures how fast a model runs on this machine and sends the numbers to vsmacs.com.
# Sends: model, tokens/sec, load time, chip name, total RAM, OS. Nothing else.
set -e
MODEL="${1:-qwen3:8b}"
command -v ollama >/dev/null || { echo "Install Ollama first: https://ollama.com"; exit 1; }
echo "Pulling $MODEL (skip if you have it)..."; ollama pull "$MODEL" >/dev/null
chip=$(sysctl -n machdep.cpu.brand_string 2>/dev/null || grep -m1 "model name" /proc/cpuinfo | cut -d: -f2 | sed 's/^ //')
gpu=$(system_profiler SPDisplaysDataType 2>/dev/null | awk -F: '/Chipset Model/{gsub(/^ /,"",$2);print $2;exit}')
[ -z "$gpu" ] && gpu=$(lspci 2>/dev/null | grep -Ei "vga|3d" | head -1 | cut -d: -f3 | sed 's/^ //')
ram=$(( $(sysctl -n hw.memsize 2>/dev/null || awk '/MemTotal/{print $2*1024}' /proc/meminfo) / 1073741824 ))
os=$(uname -sr)
run() { curl -s http://127.0.0.1:11434/api/generate -d "{\"model\":\"$MODEL\",\"prompt\":\"$1\",\"stream\":false,\"options\":{\"num_predict\":300,\"temperature\":0}}"; }
echo "Warm-up run..."; run "Say hi." >/dev/null
echo "Measuring..."; R=$(run "Explain how memory bandwidth limits local LLM speed, in about 250 words.")
body=$(printf '{"model":"%s","chip":"%s","gpu":"%s","ram_gb":%s,"os":"%s","result":%s}' "$MODEL" "$chip" "$gpu" "$ram" "$os" "$R")
echo "$R" | grep -q eval_count || { echo "Ollama didn't return timings. Is it running? (ollama serve)"; exit 1; }
printf '%s' "$body" | curl -s -X POST -H 'content-type: application/json' --data-binary @- https://vsmacs.com/api/submit
echo
