Files
hakorune/tools/perf/dual_emit_compare.sh
nyash-codex dda65b94b7 Phase 21.7 normalization: optimization pre-work + bench harness expansion
- Add opt-in optimizations (defaults OFF)
  - Ret purity verifier: NYASH_VERIFY_RET_PURITY=1
  - strlen FAST enhancement for const handles
  - FAST_INT gate for same-BB SSA optimization
  - length cache for string literals in llvmlite
- Expand bench harness (tools/perf/microbench.sh)
  - Add branch/call/stringchain/arraymap/chip8/kilo cases
  - Auto-calculate ratio vs C reference
  - Document in benchmarks/README.md
- Compiler health improvements
  - Unify PHI insertion to insert_phi_at_head()
  - Add NYASH_LLVM_SKIP_BUILD=1 for build reuse
- Runtime & safety enhancements
  - Clarify Rust/Hako ownership boundaries
  - Strengthen receiver localization (LocalSSA/pin/after-PHIs)
  - Stop excessive PluginInvoke→BoxCall rewrites
- Update CURRENT_TASK.md, docs, and canaries

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 16:40:58 +09:00

67 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# dual_emit_compare.sh — Dualemit MIR(JSON) (provider vs selfhost) and compare + bench
# Usage: tools/perf/dual_emit_compare.sh <input.hako> [rounds]
# Output: human summary + CSV snippets (provider/selfhost benches)
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <input.hako> [rounds]" >&2
exit 2
fi
IN="$1"; ROUNDS="${2:-3}"
ROOT="$(cd "$(dirname "$0")"/../.. && pwd)"
EMIT="$ROOT/tools/hakorune_emit_mir.sh"
BENCH="$ROOT/tools/perf/bench_hakorune_emit_mir.sh"
CMP="$ROOT/tools/perf/compare_mir_json.sh"
for f in "$EMIT" "$BENCH" "$CMP"; do
[[ -x "$f" ]] || { echo "error: missing executable: $f" >&2; exit 2; }
done
[[ -f "$IN" ]] || { echo "error: input not found: $IN" >&2; exit 2; }
prov_csv=$(HAKO_SELFHOST_BUILDER_FIRST=0 "$BENCH" "$IN" "$ROUNDS" || true)
self_csv=$(HAKO_SELFHOST_BUILDER_FIRST=1 "$BENCH" "$IN" "$ROUNDS" || true)
calc_stats() {
# stdin: CSV header then rows: round,ms,size,sha1
awk -F, 'NR>1 && $2 ~ /^[0-9]+$/ { n++; s+=$2; arr[n]=$2 } END {
if (n==0) { print "count=0 avg=NA p50=NA"; exit }
asort(arr)
p50 = (n%2==1)? arr[(n+1)/2] : (arr[n/2]+arr[n/2+1])/2
printf("count=%d avg=%.0f p50=%.0f\n", n, (s/n), p50)
}'
}
prov_stats=$(printf '%s\n' "$prov_csv" | calc_stats)
self_stats=$(printf '%s\n' "$self_csv" | calc_stats)
OUT_PROV="/tmp/dual_mir_provider_$$.json"
OUT_SELF="/tmp/dual_mir_selfhost_$$.json"
trap 'rm -f "$OUT_PROV" "$OUT_SELF" || true' EXIT
# Produce concrete MIR JSONs
HAKO_SELFHOST_BUILDER_FIRST=0 "$EMIT" "$IN" "$OUT_PROV" >/dev/null 2>&1 || true
HAKO_SELFHOST_BUILDER_FIRST=1 "$EMIT" "$IN" "$OUT_SELF" >/dev/null 2>&1 || true
echo "== DualEmit Bench Summary =="
echo "input: $IN rounds: $ROUNDS"
echo "provider: $prov_stats"
echo "selfhost: $self_stats"
if [[ -s "$OUT_PROV" && -s "$OUT_SELF" ]]; then
echo "\n== Structural Compare (normalized) =="
"$CMP" "$OUT_PROV" "$OUT_SELF" || true
else
echo "\n[warn] one or both MIR outputs missing. Check bench CSV for ERROR rows." >&2
fi
echo "\n== Provider CSV =="
printf '%s\n' "$prov_csv" | sed -n '1,20p'
echo "\n== Selfhost CSV =="
printf '%s\n' "$self_csv" | sed -n '1,20p'
exit 0