{"schema_version":1,"methodology":"Semantically matched, single-threaded, prepared execution with shared checksums. No implementation-specific type declarations.","workloads":[{"id":"sieve-array","category":"Arrays & loops","group":"integer-array","operations":512,"expected":"54","implementations":{"hara":{"language":"Hara","source":"(let [flags (std.native.Arr/new 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) ] (loop [p 2] (if (< (* p p) 256) (do (if (= (std.native.Arr/get-index flags p) 1) (loop [k (* p p)] (if (< k 256) (do (std.native.Arr/set-index flags k 0) (recur (+ k p))) nil)) nil) (recur (+ p 1))) (loop [i 2 count 0] (if (< i 256) (recur (+ i 1) (+ count (std.native.Arr/get-index flags i))) count)))))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(let ((flags (make-array 256 :initial-element 1))) (loop for p from 2 while (< (* p p) 256) when (= (aref flags p) 1) do (loop for k from (* p p) below 256 by p do (setf (aref flags k) 0))) (loop for i from 2 below 256 sum (aref flags i)))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(let ((flags (make-vector 256 1))) (let loop-p ((p 2)) (if (< (* p p) 256) (begin (if (= (vector-ref flags p) 1) (let loop-k ((k (* p p))) (if (< k 256) (begin (vector-set! flags k 0) (loop-k (+ k p))))) #f) (loop-p (+ p 1))) (let loop-i ((i 2) (count 0)) (if (< i 256) (loop-i (+ i 1) (+ count (vector-ref flags i))) count)))))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(let ((flags (make-vector 256 1))) (let loop-p ((p 2)) (if (< (* p p) 256) (begin (if (= (vector-ref flags p) 1) (let loop-k ((k (* p p))) (if (< k 256) (begin (vector-set! flags k 0) (loop-k (+ k p))))) #f) (loop-p (+ p 1))) (let loop-i ((i 2) (count 0)) (if (< i 256) (loop-i (+ i 1) (+ count (vector-ref flags i))) count)))))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local flags={} for i=1,256 do flags[i]=1 end for p=2,15 do if flags[p+1]==1 then for k=p*p,255,p do flags[k+1]=0 end end end local count=0 for i=2,255 do count=count+flags[i+1] end return count","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(let [flags (int-array 256 1)] (loop [p 2] (when (< (* p p) 256) (when (= (aget flags p) 1) (loop [k (* p p)] (when (< k 256) (aset-int flags k 0) (recur (+ k p))))) (recur (inc p)))) (loop [i 2 count 0] (if (< i 256) (recur (inc i) (+ count (aget flags i))) count)))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def benchmark():\n    flags=[1]*256\n    for p in range(2,16):\n        if flags[p]:\n            for k in range(p*p,256,p): flags[k]=0\n    return sum(flags[2:])","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"int64_t benchmark(void) { volatile int flags[256]; int one=1+(int)benchmark_seed; for (int i=0;i<256;i++) flags[i]=one; for (int p=2;p*p<256;p++) if (flags[p]) for (int k=p*p;k<256;k+=p) flags[k]=0; int64_t total=0; for (int i=2;i<256;i++) total+=flags[i]; return total; }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static long benchmark() { int[] flags=new int[256]; java.util.Arrays.fill(flags,1); for(int p=2;p*p<256;p++) if(flags[p]!=0) for(int k=p*p;k<256;k+=p) flags[k]=0; long total=0; for(int i=2;i<256;i++) total+=flags[i]; return total; }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"towers-recursive","category":"Recursion","group":"integer-recursion","operations":262143,"expected":"262143","implementations":{"hara":{"language":"Hara","source":"(do (defn general-towers [n] (if (= n 0) 0 (+ 1 (general-towers (- n 1)) (general-towers (- n 1))))) (general-towers 18))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(labels ((towers (n) (if (= n 0) 0 (+ 1 (towers (1- n)) (towers (1- n)))))) (towers 18))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(letrec ((towers (lambda (n) (if (= n 0) 0 (+ 1 (towers (- n 1)) (towers (- n 1))))))) (towers 18))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(letrec ((towers (lambda (n) (if (= n 0) 0 (+ 1 (towers (- n 1)) (towers (- n 1))))))) (towers 18))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local function towers(n) if n==0 then return 0 end return 1+towers(n-1)+towers(n-1) end return towers(18)","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(letfn [(towers [n] (if (zero? n) 0 (+ 1 (towers (dec n)) (towers (dec n)))))] (towers 18))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def towers(n):\n    return 0 if n==0 else 1+towers(n-1)+towers(n-1)\ndef benchmark(): return towers(18)","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"__attribute__((noinline)) static int64_t towers(int n) { return n==0 ? benchmark_seed : 1+towers(n-1)+towers(n-1); } int64_t benchmark(void) { return towers(18+(int)benchmark_seed); }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static long towers(int n) { return n==0 ? 0 : 1+towers(n-1)+towers(n-1); } static long benchmark() { return towers(18); }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"queens-backtracking","category":"Search & mutation","group":"search-mutable-array","operations":15720,"expected":"92","implementations":{"hara":{"language":"Hara","source":"(do (defn general-queens-safe [cols row col] (loop [prior 0] (if (< prior row) (let [placed (std.native.Arr/get-index cols prior) delta (- placed col) distance (- row prior)] (if (= placed col) 0 (if (= (if (< delta 0) (- 0 delta) delta) distance) 0 (recur (+ prior 1))))) 1))) (defn general-queens-place [cols row] (if (= row 8) 1 (loop [col 0 count 0] (if (< col 8) (if (= (general-queens-safe cols row col) 1) (do (std.native.Arr/set-index cols row col) (recur (+ col 1) (+ count (general-queens-place cols (+ row 1))))) (recur (+ col 1) count)) count)))) (general-queens-place (std.native.Arr/new 0 0 0 0 0 0 0 0) 0))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(let ((cols (make-array 8 :initial-element 0))) (labels ((safe-p (row col) (loop for prior below row for placed = (aref cols prior) always (and (/= placed col) (/= (abs (- placed col)) (- row prior))))) (place (row) (if (= row 8) 1 (loop for col below 8 when (safe-p row col) sum (progn (setf (aref cols row) col) (place (1+ row))))))) (place 0)))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(let ((cols (make-vector 8 0))) (letrec ((safe? (lambda (row col) (let loop ((prior 0)) (if (< prior row) (let* ((placed (vector-ref cols prior)) (delta (- placed col)) (distance (- row prior))) (if (or (= placed col) (= (abs delta) distance)) #f (loop (+ prior 1)))) #t)))) (place (lambda (row) (if (= row 8) 1 (let loop ((col 0) (count 0)) (if (< col 8) (if (safe? row col) (begin (vector-set! cols row col) (loop (+ col 1) (+ count (place (+ row 1))))) (loop (+ col 1) count)) count)))))) (place 0)))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(let ((cols (make-vector 8 0))) (letrec ((safe? (lambda (row col) (let loop ((prior 0)) (if (< prior row) (let* ((placed (vector-ref cols prior)) (delta (- placed col)) (distance (- row prior))) (if (or (= placed col) (= (abs delta) distance)) #f (loop (+ prior 1)))) #t)))) (place (lambda (row) (if (= row 8) 1 (let loop ((col 0) (count 0)) (if (< col 8) (if (safe? row col) (begin (vector-set! cols row col) (loop (+ col 1) (+ count (place (+ row 1))))) (loop (+ col 1) count)) count)))))) (place 0)))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local cols={} local function safe(row,col) for prior=0,row-1 do local placed=cols[prior+1] if placed==col or math.abs(placed-col)==row-prior then return false end end return true end local function place(row) if row==8 then return 1 end local count=0 for col=0,7 do if safe(row,col) then cols[row+1]=col count=count+place(row+1) end end return count end return place(0)","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(let [cols (int-array 8)] (letfn [(safe? [row col] (loop [prior 0] (if (< prior row) (let [placed (aget cols prior)] (if (or (= placed col) (= (abs (- placed col)) (- row prior))) false (recur (inc prior)))) true))) (place [row] (if (= row 8) 1 (loop [col 0 count 0] (if (< col 8) (if (safe? row col) (do (aset-int cols row col) (recur (inc col) (+ count (place (inc row))))) (recur (inc col) count)) count))))] (place 0)))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def benchmark():\n    cols=[0]*8\n    def safe(row,col):\n        return all(cols[p]!=col and abs(cols[p]-col)!=row-p for p in range(row))\n    def place(row):\n        if row==8: return 1\n        total=0\n        for col in range(8):\n            if safe(row,col): cols[row]=col; total+=place(row+1)\n        return total\n    return place(0)","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"static int cols[8]; static int safe(int row,int col) { for(int p=0;p<row;p++) { int d=cols[p]-col; if(cols[p]==col || (d<0?-d:d)==row-p) return 0; } return 1; } static int64_t place(int row) { if(row==8) return 1; int64_t total=0; for(int col=0;col<8;col++) if(safe(row,col)) { cols[row]=col; total+=place(row+1); } return total; } int64_t benchmark(void) { return place(0); }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static int[] cols=new int[8]; static boolean safe(int row,int col) { for(int p=0;p<row;p++) if(cols[p]==col || Math.abs(cols[p]-col)==row-p) return false; return true; } static long place(int row) { if(row==8) return 1; long total=0; for(int col=0;col<8;col++) if(safe(row,col)) { cols[row]=col; total+=place(row+1); } return total; } static long benchmark() { return place(0); }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"heap-permute","category":"Search & mutation","group":"recursion-mutable-array","operations":40320,"expected":"40320","implementations":{"hara":{"language":"Hara","source":"(do (defn general-permute [values n] (if (= n 1) 1 (loop [i 0 count 0] (if (< i n) (let [subtotal (general-permute values (- n 1)) j (if (= (mod n 2) 0) i 0) left (std.native.Arr/get-index values j) right (std.native.Arr/get-index values (- n 1))] (std.native.Arr/set-index values j right) (std.native.Arr/set-index values (- n 1) left) (recur (+ i 1) (+ count subtotal))) count)))) (general-permute (std.native.Arr/new 0 1 2 3 4 5 6 7) 8))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(let ((values (vector 0 1 2 3 4 5 6 7))) (labels ((permute (n) (if (= n 1) 1 (loop for i below n for subtotal = (permute (1- n)) for j = (if (evenp n) i 0) do (rotatef (aref values j) (aref values (1- n))) sum subtotal)))) (permute 8)))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(let ((values (vector 0 1 2 3 4 5 6 7))) (letrec ((permute (lambda (n) (if (= n 1) 1 (let loop ((i 0) (count 0)) (if (< i n) (let* ((subtotal (permute (- n 1))) (j (if (= (modulo n 2) 0) i 0)) (left (vector-ref values j)) (right (vector-ref values (- n 1)))) (vector-set! values j right) (vector-set! values (- n 1) left) (loop (+ i 1) (+ count subtotal))) count)))))) (permute 8)))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(let ((values (vector 0 1 2 3 4 5 6 7))) (letrec ((permute (lambda (n) (if (= n 1) 1 (let loop ((i 0) (count 0)) (if (< i n) (let* ((subtotal (permute (- n 1))) (j (if (= (modulo n 2) 0) i 0)) (left (vector-ref values j)) (right (vector-ref values (- n 1)))) (vector-set! values j right) (vector-set! values (- n 1) left) (loop (+ i 1) (+ count subtotal))) count)))))) (permute 8)))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local values={0,1,2,3,4,5,6,7} local function permute(n) if n==1 then return 1 end local count=0 for i=0,n-1 do count=count+permute(n-1) local j=(n%2==0) and i or 0 values[j+1],values[n]=values[n],values[j+1] end return count end return permute(8)","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(let [values (int-array (range 8))] (letfn [(permute [n] (if (= n 1) 1 (loop [i 0 count 0] (if (< i n) (let [subtotal (permute (dec n)) j (if (even? n) i 0) left (aget values j) right (aget values (dec n))] (aset-int values j right) (aset-int values (dec n) left) (recur (inc i) (+ count subtotal))) count))))] (permute 8)))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def benchmark():\n    values=list(range(8))\n    def permute(n):\n        if n==1: return 1\n        total=0\n        for i in range(n):\n            total+=permute(n-1); j=i if n%2==0 else 0; values[j],values[n-1]=values[n-1],values[j]\n        return total\n    return permute(8)","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"static int values[8]; static int64_t permute(int n) { if(n==1) return 1; int64_t total=0; for(int i=0;i<n;i++) { total+=permute(n-1); int j=n%2==0?i:0, x=values[j]; values[j]=values[n-1]; values[n-1]=x; } return total; } int64_t benchmark(void) { for(int i=0;i<8;i++) values[i]=i; return permute(8); }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static int[] values=new int[8]; static long permute(int n) { if(n==1) return 1; long total=0; for(int i=0;i<n;i++) { total+=permute(n-1); int j=n%2==0?i:0,x=values[j]; values[j]=values[n-1]; values[n-1]=x; } return total; } static long benchmark() { for(int i=0;i<8;i++) values[i]=i; return permute(8); }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"ackermann-deep","category":"Recursion","group":"deep-non-tail-recursion","operations":2785999,"expected":"2045","implementations":{"hara":{"language":"Hara","source":"(do (defn general-ack [m n] (if (= m 0) (+ n 1) (if (= n 0) (general-ack (- m 1) 1) (general-ack (- m 1) (general-ack m (- n 1)))))) (general-ack 3 8))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(labels ((ack (m n) (if (= m 0) (1+ n) (if (= n 0) (ack (1- m) 1) (ack (1- m) (ack m (1- n))))))) (ack 3 8))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(letrec ((ack (lambda (m n) (if (= m 0) (+ n 1) (if (= n 0) (ack (- m 1) 1) (ack (- m 1) (ack m (- n 1)))))))) (ack 3 8))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(letrec ((ack (lambda (m n) (if (= m 0) (+ n 1) (if (= n 0) (ack (- m 1) 1) (ack (- m 1) (ack m (- n 1)))))))) (ack 3 8))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local function ack(m,n) if m==0 then return n+1 elseif n==0 then return ack(m-1,1) else return ack(m-1,ack(m,n-1)) end end return ack(3,8)","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(letfn [(ack [m n] (if (zero? m) (inc n) (if (zero? n) (ack (dec m) 1) (ack (dec m) (ack m (dec n))))))] (ack 3 8))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def ack(m,n):\n    return n+1 if m==0 else ack(m-1,1) if n==0 else ack(m-1,ack(m,n-1))\ndef benchmark(): return ack(3,8)","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"__attribute__((noinline)) static int64_t ack(int m,int64_t n) { return m==0 ? n+1+benchmark_seed : n==0 ? ack(m-1,1) : ack(m-1,ack(m,n-1)); } int64_t benchmark(void) { return ack(3,8+benchmark_seed); }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static long ack(int m,long n) { return m==0 ? n+1 : n==0 ? ack(m-1,1) : ack(m-1,ack(m,n-1)); } static long benchmark() { return ack(3,8); }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"tak-branching","category":"Recursion","group":"branching-non-tail-recursion","operations":63609,"expected":"7","implementations":{"hara":{"language":"Hara","source":"(do (defn general-tak [x y z] (if (<= x y) z (general-tak (general-tak (- x 1) y z) (general-tak (- y 1) z x) (general-tak (- z 1) x y)))) (general-tak 18 12 6))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(labels ((tak (x y z) (if (<= x y) z (tak (tak (1- x) y z) (tak (1- y) z x) (tak (1- z) x y))))) (tak 18 12 6))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(letrec ((tak (lambda (x y z) (if (<= x y) z (tak (tak (- x 1) y z) (tak (- y 1) z x) (tak (- z 1) x y)))))) (tak 18 12 6))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(letrec ((tak (lambda (x y z) (if (<= x y) z (tak (tak (- x 1) y z) (tak (- y 1) z x) (tak (- z 1) x y)))))) (tak 18 12 6))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local function tak(x,y,z) if x<=y then return z end return tak(tak(x-1,y,z),tak(y-1,z,x),tak(z-1,x,y)) end return tak(18,12,6)","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(letfn [(tak [x y z] (if (<= x y) z (tak (tak (dec x) y z) (tak (dec y) z x) (tak (dec z) x y))))] (tak 18 12 6))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def tak(x,y,z):\n    return z if x<=y else tak(tak(x-1,y,z),tak(y-1,z,x),tak(z-1,x,y))\ndef benchmark(): return tak(18,12,6)","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"__attribute__((noinline)) static int64_t tak(int64_t x,int64_t y,int64_t z) { return x<=y ? z+benchmark_seed : tak(tak(x-1,y,z),tak(y-1,z,x),tak(z-1,x,y)); } int64_t benchmark(void) { return tak(18+benchmark_seed,12,6); }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static long tak(long x,long y,long z) { return x<=y ? z : tak(tak(x-1,y,z),tak(y-1,z,x),tak(z-1,x,y)); } static long benchmark() { return tak(18,12,6); }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"collatz-range","category":"Irregular control","group":"irregular-integer-control","operations":849666,"expected":"849666","implementations":{"hara":{"language":"Hara","source":"(do (defn general-collatz [n] (loop [value n steps 0] (if (= value 1) steps (recur (if (= (mod value 2) 0) (/ value 2) (+ (* value 3) 1)) (+ steps 1))))) (loop [n 1 total 0] (if (<= n 10000) (recur (+ n 1) (+ total (general-collatz n))) total)))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(labels ((collatz (n) (loop with value = n with steps = 0 until (= value 1) do (setf value (if (evenp value) (truncate value 2) (1+ (* value 3)))) (incf steps) finally (return steps)))) (loop for n from 1 to 10000 sum (collatz n)))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(letrec ((collatz (lambda (n) (let loop ((value n) (steps 0)) (if (= value 1) steps (loop (if (= (modulo value 2) 0) (quotient value 2) (+ (* value 3) 1)) (+ steps 1))))))) (let loop ((n 1) (total 0)) (if (<= n 10000) (loop (+ n 1) (+ total (collatz n))) total)))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(letrec ((collatz (lambda (n) (let loop ((value n) (steps 0)) (if (= value 1) steps (loop (if (= (modulo value 2) 0) (quotient value 2) (+ (* value 3) 1)) (+ steps 1))))))) (let loop ((n 1) (total 0)) (if (<= n 10000) (loop (+ n 1) (+ total (collatz n))) total)))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local function collatz(n) local steps=0 while n~=1 do if n%2==0 then n=n/2 else n=3*n+1 end steps=steps+1 end return steps end local total=0 for n=1,10000 do total=total+collatz(n) end return total","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(letfn [(collatz [n] (loop [value n steps 0] (if (= value 1) steps (recur (if (even? value) (quot value 2) (inc (* value 3))) (inc steps)))))] (loop [n 1 total 0] (if (<= n 10000) (recur (inc n) (+ total (collatz n))) total)))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def benchmark():\n    total=0\n    for n in range(1,10001):\n        steps=0\n        while n!=1:\n            n=n//2 if n%2==0 else 3*n+1; steps+=1\n        total+=steps\n    return total","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"int64_t benchmark(void) { int64_t total=0; for(int64_t n=1;n<=10000;n++) { int64_t value=n; while(value!=1) { value=value%2==0?value/2:3*value+1; total++; } } return total; }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static long benchmark() { long total=0; for(long n=1;n<=10000;n++) { long value=n; while(value!=1) { value=value%2==0?value/2:3*value+1; total++; } } return total; }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}},{"id":"matrix-multiply","category":"Arrays & loops","group":"nested-loops-mutable-array","operations":6400,"expected":"4156","implementations":{"hara":{"language":"Hara","source":"(let [a (std.native.Arr/new 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16) b (std.native.Arr/new 1 4 7 10 13 16 2 5 8 11 14 0 3 6 9 12) c (std.native.Arr/new 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)] (loop [iteration 0] (if (< iteration 100) (do (loop [row 0] (if (< row 4) (do (loop [col 0] (if (< col 4) (do (std.native.Arr/set-index c (+ (* row 4) col) (loop [k 0 total 0] (if (< k 4) (recur (+ k 1) (+ total (* (std.native.Arr/get-index a (+ (* row 4) k)) (std.native.Arr/get-index b (+ (* k 4) col))))) total))) (recur (+ col 1))) nil)) (recur (+ row 1))) nil)) (recur (+ iteration 1))) (loop [i 0 total 0] (if (< i 16) (recur (+ i 1) (+ total (std.native.Arr/get-index c i))) total)))))","harness":"#!/usr/bin/env python3\n\"\"\"Lisp (SBCL / Chez Scheme / Guile) vs Hara (Rust native) comparison\nbenchmark coordinator.\n\nModelled on lib/bench/luajit-hara/run.py: windowed sampling, steady-state\nmedian analysis, JSON + Markdown output. Results default to target/\n(gitignored scratch) \u2014 this is comparison evidence, not regression gating.\n\"\"\"\n\nfrom __future__ import annotations\n\nimport argparse\nimport datetime as dt\nimport json\nimport math\nimport os\nimport platform\nimport shutil\nimport statistics\nimport subprocess\nimport time\nfrom pathlib import Path\n\nBENCH_ROOT = Path(os.environ.get(\"HARA_BENCH_ROOT\", Path(__file__).resolve().parents[2]))\nROOT = Path(os.environ.get(\"HARA_ROOT\", BENCH_ROOT / \"vendor/hara\"))\nHERE = BENCH_ROOT / \"suites/language\"\nDEFAULT_CORPUS = HERE / \"workloads.json\"\nCHEZ_RUNNER = HERE / \"chez_runner.scm\"\nGUILE_RUNNER = HERE / \"guile_runner.scm\"\nSBCL_RUNNER = HERE / \"sbcl_runner.lisp\"\nBB_RUNNER = HERE / \"bb_runner.clj\"\nPYTHON_RUNNER = HERE / \"python_runner.py\"\nC_RUNNER = HERE / \"c_runner.py\"\nJAVA_RUNNER = HERE / \"java_runner.py\"\nLUA_RUNNER = BENCH_ROOT / \"adapters/luajit/lua_runner.lua\"\nHARA_BENCH = ROOT / \"rust/target/release/hara-runtime-benchmark\"\n\nPROFILES = {\n    \"smoke\": {\"startup_samples\": 2, \"windows\": 3, \"calls\": 1},\n    \"algorithm\": {\"startup_samples\": 10, \"windows\": 30, \"calls\": 3},\n    \"standard\": {\"startup_samples\": 30, \"windows\": 60, \"calls\": 10},\n}\n\nLISP_RUNTIMES = {\n    \"sbcl\": {\"command\": [\"sbcl\", \"--script\", str(SBCL_RUNNER)],\n             \"source_field\": \"cl_source\", \"binary\": \"sbcl\"},\n    \"chez\": {\"command\": [\"chez\", \"--script\", str(CHEZ_RUNNER)],\n             \"source_field\": \"scheme_source\", \"binary\": \"chez\"},\n    \"guile\": {\"command\": [\"guile\", \"-s\", str(GUILE_RUNNER)],\n              \"source_field\": \"scheme_source\", \"binary\": \"guile\"},\n}\n\nLANGUAGE_RUNTIMES = {**LISP_RUNTIMES,\n                     \"bb\": {\"command\": [\"bb\", str(BB_RUNNER)],\n                            \"source_field\": \"bb_source\", \"binary\": \"bb\"},\n                     \"python\": {\"command\": [\"python3\", str(PYTHON_RUNNER)],\n                                \"source_field\": \"python_source\", \"binary\": \"python3\"},\n                     \"c\": {\"command\": [\"python3\", str(C_RUNNER)],\n                           \"source_field\": \"c_source\", \"binary\": \"cc\",\n                           \"modes\": (\"prepared\",)},\n                     \"java\": {\"command\": [\"python3\", str(JAVA_RUNNER)],\n                              \"source_field\": \"java_source\", \"binary\": \"python3\",\n                              \"modes\": (\"prepared\",)},\n                     \"luajit\": {\"command\": [\"luajit\", str(LUA_RUNNER)],\n                                \"source_field\": \"lua_source\", \"binary\": \"luajit\"}}\n\n\ndef run(command, *, timeout=180, check=True):\n    return subprocess.run(command, cwd=ROOT, text=True,\n                          capture_output=True, timeout=timeout, check=check)\n\n\ndef version(command):\n    try:\n        result = run(command, check=False, timeout=20)\n        text = (result.stdout or result.stderr).strip().splitlines()\n        return text[0] if text else \"unknown\"\n    except (OSError, subprocess.SubprocessError):\n        return \"unavailable\"\n\n\ndef hex_payload(source):\n    return source.encode().hex()\n\n\nBYTECODE_VARIANTS = {\n    \"hara-rust-bytecode\": (\"bytecode-vm\", \"vm\"),\n    \"hara-rust-trace-checked\": (\"tracing-jit\", \"trace-checked\"),\n    \"hara-rust-trace-native\": (\"native-jit\", \"trace-native\"),\n    \"hara-rust-whole-wasm\": (\"whole-wasm\", \"whole-wasm\"),\n}\n\n\ndef bytecode_binary(label):\n    return ROOT / \"target/runtime-benchmark\" / label / \"release/hara-bytecode-benchmark\"\n\n\ndef build_bytecode(selected):\n    for runtime, (features, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" not in selected and\n                not (runtime == \"hara-rust-bytecode\" and\n                     \"hara-rust-bytecode-eval\" in selected)):\n            continue\n        env = os.environ.copy()\n        env[\"CARGO_TARGET_DIR\"] = str(ROOT / \"target/runtime-benchmark\" / label)\n        subprocess.run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\",\n                        \"--release\", \"--features\", features,\n                        \"--bin\", \"hara-bytecode-benchmark\"],\n                       cwd=ROOT, env=env, check=True, timeout=600)\n\n\ndef adapters():\n    def bytecode(binary, runtime, mode, workload, windows, calls):\n        return [str(binary), mode, workload[\"id\"],\n                hex_payload(workload[\"hara_source\"]), workload[\"expected\"],\n                str(windows), str(calls), runtime]\n\n    def language(name, mode, workload, windows, calls):\n        spec = LANGUAGE_RUNTIMES[name]\n        source = workload.get(spec[\"source_field\"], workload[\"hara_source\"])\n        return spec[\"command\"] + [\n            mode, workload[\"id\"], hex_payload(source),\n            workload[\"expected\"], str(windows), str(calls)]\n\n    result = {\n        \"hara-rust-native-eval\": lambda w, n, c: [\n            str(HARA_BENCH), \"hara-rust-native-eval\", w[\"id\"],\n            hex_payload(w[\"hara_source\"]), w[\"expected\"], str(n), str(c)],\n    }\n    for name in LANGUAGE_RUNTIMES:\n        for mode in LANGUAGE_RUNTIMES[name].get(\"modes\", (\"eval\", \"prepared\")):\n            label = f\"{name}-{mode}\"\n            result[label] = lambda w, n, c, name=name, mode=mode: language(\n                name, mode, w, n, c)\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if runtime == \"hara-rust-whole-wasm\":\n            result[f\"{runtime}-prepared\"] = (\n                lambda w, n, c, b=bytecode_binary(label), r=runtime:\n                bytecode(b, f\"{r}-prepared\", \"whole-wasm\", w, n, c))\n            continue\n        result[f\"{runtime}-prepared\"] = (\n            lambda w, n, c, b=bytecode_binary(label), r=runtime:\n            bytecode(b, f\"{r}-prepared\", \"runtime-registry-execute\", w, n, c))\n    result[\"hara-rust-bytecode-eval\"] = (\n        lambda w, n, c, b=bytecode_binary(\"vm\"):\n        bytecode(b, \"hara-rust-bytecode-eval\", \"compile-execute\", w, n, c))\n    return result\n\n\ndef percentile(values, fraction):\n    ordered = sorted(values)\n    return ordered[min(len(ordered) - 1, math.ceil((len(ordered) - 1) * fraction))]\n\n\ndef analyse(samples):\n    tail = samples[-10:]\n    reference = statistics.median(tail)\n    converged = None\n    for index in range(0, max(0, len(samples) - 4)):\n        window = samples[index:index + 5]\n        if all(abs(value - reference) <= reference * 0.05 for value in window):\n            mean = statistics.mean(window)\n            cv = statistics.pstdev(window) / mean if mean else 0\n            if cv <= 0.10:\n                converged = index\n                break\n    return {\"steady_ns\": int(reference),\n            \"throughput_per_sec\": 1e9 / reference if reference else None,\n            \"converged_window\": converged, \"converged\": converged is not None}\n\n\ndef timed(command):\n    started = time.perf_counter_ns()\n    result = run(command, timeout=1200)\n    elapsed = time.perf_counter_ns() - started\n    line = next(line for line in reversed(result.stdout.splitlines())\n                if line.startswith(\"{\"))\n    return elapsed, json.loads(line)\n\n\ndef markdown(data):\n    lisps = [name for name in data[\"runtime_order\"]\n             if name.split(\"-\")[0] in LANGUAGE_RUNTIMES]\n    hara_tiers = [name for name in data[\"runtime_order\"] if name not in lisps]\n    lines = [\"# Lisp vs Hara (Rust native) benchmark\", \"\",\n             f\"Generated: `{data['environment']['timestamp']}` on \"\n             f\"`{data['environment']['platform']}`.\", \"\",\n             \"Values are machine-specific comparison evidence, not regression \"\n             \"thresholds. `-eval` rows include source loading on every call; \"\n             \"`-prepared` rows compile/load once and invoke repeatedly. Rows \"\n             \"from different lanes are not apples-to-apples.\", \"\",\n             \"## Startup\", \"\", \"| Runtime | p50 ms | p95 ms |\", \"|---|---:|---:|\"]\n    for name, item in data[\"startup\"].items():\n        if item.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {name} | \u2014 | \u2014 |\")\n        else:\n            lines.append(f\"| {name} | {item['p50_ns']/1e6:.2f} | {item['p95_ns']/1e6:.2f} |\")\n    lines += [\"\", \"## Warm evaluation\", \"\",\n              \"| Runtime / workload | First ms | Steady ms | ns/iteration | calls/s | Converged window |\",\n              \"|---|---:|---:|---:|---:|---:|\"]\n    for row in data[\"measurements\"]:\n        if row.get(\"status\") == \"unsupported\":\n            lines.append(f\"| {row['runtime']} / {row['workload']} | \u2014 | \u2014 | \u2014 | \u2014 | \u2014 |\")\n            continue\n        convergence = row[\"analysis\"][\"converged_window\"]\n        per_iteration = row[\"analysis\"].get(\"ns_per_iteration\")\n        per_iteration_text = \"\u2014\" if per_iteration is None else f\"{per_iteration:.2f}\"\n        throughput = row[\"analysis\"][\"throughput_per_sec\"]\n        throughput_text = \"\u2014\" if throughput is None else f\"{throughput:.1f}\"\n        lines.append(\n            f\"| {row['runtime']} / {row['workload']} | {row['first_ns']/1e6:.3f} \"\n            f\"| {row['analysis']['steady_ns']/1e6:.3f} | {per_iteration_text} \"\n            f\"| {throughput_text} \"\n            f\"| {convergence if convergence is not None else '\u2014'} |\")\n    lines += [\"\", \"## Feature coverage\", \"\", \"| Runtime / workload | Status | Detail |\",\n              \"|---|---|---|\"]\n    for row in data[\"measurements\"]:\n        status = row.get(\"status\", \"ok\")\n        detail = row.get(\"reason\", \"checksum verified\").replace(\"|\", \"\\\\|\")\n        lines.append(f\"| {row['runtime']} / {row['workload']} | {status} | {detail} |\")\n    lines += [\"\", \"## Head-to-head (steady state, lisp / hara tier)\", \"\",\n              \"| Workload | Lisp | Hara tier | Lisp steady ms | Hara steady ms | Ratio |\",\n              \"|---|---|---|---:|---:|---:|\"]\n    index = {(m[\"runtime\"], m[\"workload\"]): m for m in data[\"measurements\"]}\n    for workload in data[\"workload_ids\"]:\n        for lisp in lisps:\n            base = index.get((lisp, workload))\n            for tier in hara_tiers:\n                hara = index.get((tier, workload))\n                if (base and hara and base.get(\"status\") == \"ok\"\n                        and hara.get(\"status\") == \"ok\"):\n                    lisp_ns = base[\"analysis\"][\"steady_ns\"]\n                    hara_ns = hara[\"analysis\"][\"steady_ns\"]\n                    lines.append(f\"| {workload} | {lisp} | {tier} | {lisp_ns/1e6:.3f} \"\n                                 f\"| {hara_ns/1e6:.3f} | {lisp_ns/hara_ns:.4f} |\")\n    lines += [\"\", \"Ratio < 1 means the comparison runtime is faster. Compare \"\n              \"only rows carrying the same `-eval` or `-prepared` suffix. \"\n              \"Convergence is the first \"\n              \"five-window run within \u00b15% of the final ten-window median with \"\n              \"CV \u226410%.\", \"\"]\n    return \"\\n\".join(lines)\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"--profile\", choices=PROFILES, default=\"smoke\")\n    parser.add_argument(\"--runtime\", action=\"append\")\n    parser.add_argument(\"--corpus\", type=Path, default=DEFAULT_CORPUS)\n    parser.add_argument(\"--output\", type=Path,\n                        default=ROOT / \"target/lisp-hara-benchmark.json\")\n    parser.add_argument(\"--no-build\", action=\"store_true\")\n    args = parser.parse_args()\n    profile = PROFILES[args.profile]\n    runtime_adapters = adapters()\n    selected = args.runtime or list(runtime_adapters)\n    unknown = sorted(set(selected) - set(runtime_adapters))\n    if unknown:\n        parser.error(\"unknown runtime(s): \" + \", \".join(unknown))\n\n    if not args.no_build:\n        if \"hara-rust-native-eval\" in selected:\n            run([\"cargo\", \"build\", \"--manifest-path\", \"rust/Cargo.toml\", \"--release\",\n                 \"--bin\", \"hara-runtime-benchmark\"], timeout=600)\n        build_bytecode(selected)\n    if \"hara-rust-native-eval\" in selected and not HARA_BENCH.is_file():\n        parser.error(f\"missing {HARA_BENCH} (build it or drop --no-build)\")\n    for runtime, (_, label) in BYTECODE_VARIANTS.items():\n        if (f\"{runtime}-prepared\" in selected or\n                (runtime == \"hara-rust-bytecode\" and\n                 \"hara-rust-bytecode-eval\" in selected)) and not bytecode_binary(label).is_file():\n            parser.error(f\"missing {bytecode_binary(label)} (build it or drop --no-build)\")\n    for name, spec in LANGUAGE_RUNTIMES.items():\n        if any(runtime.startswith(f\"{name}-\") for runtime in selected) and not shutil.which(spec[\"binary\"]):\n            parser.error(f\"{spec['binary']} not found on PATH \"\n                         f\"(brew install {'chezscheme' if name == 'chez' else name})\")\n\n    corpus_path = args.corpus if args.corpus.is_absolute() else ROOT / args.corpus\n    corpus = json.loads(corpus_path.read_text())[\"workloads\"]\n\n    measurements = []\n    startup = {}\n    for name in selected:\n        adapter = runtime_adapters[name]\n        elapsed = []\n        startup_workload = None\n        for candidate in corpus:\n            try:\n                wall, _ = timed(adapter(candidate, 0, 1))\n            except subprocess.CalledProcessError:\n                continue\n            startup_workload = candidate\n            elapsed.append(wall)\n            break\n        if startup_workload is None:\n            startup[name] = {\"status\": \"unsupported\",\n                             \"reason\": \"no corpus workload is supported\"}\n        else:\n            for _ in range(1, profile[\"startup_samples\"]):\n                wall, _ = timed(adapter(startup_workload, 0, 1))\n                elapsed.append(wall)\n            startup[name] = {\n                \"status\": \"ok\", \"workload\": startup_workload[\"id\"],\n                \"samples_ns\": elapsed,\n                \"p50_ns\": int(statistics.median(elapsed)),\n                \"p95_ns\": percentile(elapsed, 0.95)}\n        for workload in corpus:\n            try:\n                _, result = timed(adapter(workload, profile[\"windows\"], profile[\"calls\"]))\n            except subprocess.CalledProcessError as error:\n                message = (error.stderr or error.stdout or str(error)).strip().splitlines()\n                result = {\"runtime\": name, \"workload\": workload[\"id\"],\n                          \"status\": \"unsupported\",\n                          \"reason\": message[-1] if message else str(error)}\n                measurements.append(result)\n                print(f\"{name:30} {workload['id']:30} unsupported: {result['reason']}\")\n                continue\n            result[\"runtime\"] = name\n            result[\"analysis\"] = analyse(result[\"samples_ns\"])\n            result[\"status\"] = \"ok\"\n            operations = workload.get(\"operations\", workload.get(\"iterations\"))\n            if operations:\n                result[\"analysis\"][\"ns_per_iteration\"] = (\n                    result[\"analysis\"][\"steady_ns\"] / operations)\n            measurements.append(result)\n            print(f\"{name:18} {workload['id']:18} \"\n                  f\"{result['analysis']['steady_ns']/1e6:9.3f} ms\")\n\n    data = {\"schema_version\": 2, \"profile\": args.profile,\n            \"corpus\": str(corpus_path),\n            \"environment\": {\"timestamp\": dt.datetime.now(dt.timezone.utc).isoformat(),\n                            \"platform\": platform.platform(),\n                            \"machine\": platform.machine(),\n                            \"python\": platform.python_version(),\n                            \"git_revision\": version([\"git\", \"rev-parse\", \"HEAD\"]),\n                            \"git_dirty\": bool(run([\"git\", \"status\", \"--porcelain\"]).stdout),\n                            \"benchmark_revision\": version([\"git\", \"-C\", str(BENCH_ROOT), \"rev-parse\", \"HEAD\"])},\n            \"versions\": {\"sbcl\": version([\"sbcl\", \"--version\"]),\n                         \"chez\": version([\"chez\", \"--version\"]),\n                         \"guile\": version([\"guile\", \"--version\"]),\n                         \"luajit\": version([\"luajit\", \"-v\"]),\n                         \"bb\": version([\"bb\", \"--version\"]),\n                         \"python\": platform.python_version(),\n                         \"c\": version([\"cc\", \"--version\"]),\n                         \"java\": version([\"java\", \"--version\"]),\n                         \"javac\": version([\"javac\", \"--version\"]),\n                         \"rust\": version([\"rustc\", \"--version\"])},\n            \"workload_ids\": [w[\"id\"] for w in corpus],\n            \"runtime_order\": selected,\n            \"startup\": startup, \"measurements\": measurements}\n\n    output = args.output if args.output.is_absolute() else ROOT / args.output\n    output.parent.mkdir(parents=True, exist_ok=True)\n    output.write_text(json.dumps(data, indent=2) + \"\\n\")\n    report_path = output.with_suffix(\".md\")\n    report_path.write_text(markdown(data))\n    print(f\"wrote {output} and {report_path}\")\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/run.py","prepare":{"description":"Parse Hara \u2192 bytecode \u2192 whole-function Wasm \u2192 load module","command":"cargo build --release --features whole-wasm --bin hara-bytecode-benchmark"}},"sbcl":{"language":"Common Lisp","source":"(let ((a (vector 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)) (b (vector 1 4 7 10 13 16 2 5 8 11 14 0 3 6 9 12)) (c (make-array 16 :initial-element 0))) (dotimes (iteration 100) (dotimes (row 4) (dotimes (col 4) (setf (aref c (+ (* row 4) col)) (loop for k below 4 sum (* (aref a (+ (* row 4) k)) (aref b (+ (* k 4) col)))))))) (loop for value across c sum value))","harness":";;;; Benchmark runner for the lisp-hara comparison suite (SBCL).\n;;;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;;;   sbcl --script sbcl_runner.lisp MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;;;; Reads + evals the source on every call (matching hara's eval_native\n;;;; per-call semantics; SBCL's default *evaluator-mode* is :compile) and\n;;;; prints one JSON line:\n;;;;   {\"runtime\":\"sbcl\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(defparameter *args* (cdr sb-ext:*posix-argv*))\n\n(when (/= (length *args*) 6)\n  (format *error-output* \"sbcl_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS~%\")\n  (sb-ext:exit :code 2))\n\n(destructuring-bind (mode id source-hex expected windows-s calls-s) *args*\n  (let ((windows (parse-integer windows-s :junk-allowed t))\n        (calls (parse-integer calls-s :junk-allowed t)))\n    (unless (and windows calls)\n      (format *error-output* \"~a: invalid windows/calls~%\" id)\n      (sb-ext:exit :code 2))\n    (flet ((fail (message)\n             (format *error-output* \"~a: ~a~%\" id message)\n             (sb-ext:exit :code 1))\n           (hex-decode (s)\n             (let* ((n (length s))\n                    (out (make-string (floor n 2))))\n               (loop for i from 0 below n by 2\n                     do (setf (char out (floor i 2))\n                              (code-char (parse-integer s :start i :end (+ i 2)\n                                                          :radix 16))))\n               out))\n           (clock-ns ()\n             (round (* (/ (get-internal-run-time) internal-time-units-per-second)\n                       1d9))))\n      (let* ((source (hex-decode source-hex))\n             (form (read-from-string source))\n             (prepare-started (clock-ns))\n             (prepared (when (string= mode \"prepared\")\n                         (compile nil `(lambda () ,form))))\n             (prepare-ns (when prepared (- (clock-ns) prepare-started)))\n             (eval-once\n               (lambda ()\n                 (let ((value (if prepared (funcall prepared)\n                                  (eval (read-from-string source)))))\n                   (unless (string= (princ-to-string value) expected)\n                     (fail (format nil \"expected ~a, got ~a\" expected value))))))\n             (started (clock-ns)))\n        (funcall eval-once)\n        (let ((first-ns (- (clock-ns) started))\n              (samples '()))\n          (dotimes (w windows)\n            (let ((window-started (clock-ns)))\n              (dotimes (c calls) (funcall eval-once))\n              (push (round (/ (- (clock-ns) window-started) calls)) samples)))\n          (format t \"{\\\"runtime\\\":\\\"sbcl\\\",\\\"workload\\\":\\\"~a\\\",\\\"prepare_ns\\\":~a,\\\"first_ns\\\":~a,\\\"samples_ns\\\":[~{~a~^,~}]}~%\"\n                  id (or prepare-ns \"null\") first-ns (nreverse samples)))))))\n","harness_path":"suites/language/sbcl_runner.lisp","prepare":{"description":"Read form and compile a zero-argument lambda","command":"sbcl --script sbcl_runner.lisp prepared \u2026"}},"chez":{"language":"Scheme","source":"(let ((a (vector 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)) (b (vector 1 4 7 10 13 16 2 5 8 11 14 0 3 6 9 12)) (c (make-vector 16 0))) (do ((iteration 0 (+ iteration 1))) ((= iteration 100)) (do ((row 0 (+ row 1))) ((= row 4)) (do ((col 0 (+ col 1))) ((= col 4)) (vector-set! c (+ (* row 4) col) (do ((k 0 (+ k 1)) (total 0 (+ total (* (vector-ref a (+ (* row 4) k)) (vector-ref b (+ (* k 4) col)))))) ((= k 4) total)))))) (do ((i 0 (+ i 1)) (total 0 (+ total (vector-ref c i)))) ((= i 16) total)))","harness":";; Benchmark runner for the lisp-hara comparison suite (Chez Scheme).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   chez --script chez_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"chez\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\n(import (chezscheme))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"chez_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (let ((t (current-time)))\n    (+ (* (time-second t) 1000000000) (time-nanosecond t))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"chez\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/chez_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"chez --script chez_runner.scm prepared \u2026"}},"guile":{"language":"Scheme","source":"(let ((a (vector 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)) (b (vector 1 4 7 10 13 16 2 5 8 11 14 0 3 6 9 12)) (c (make-vector 16 0))) (do ((iteration 0 (+ iteration 1))) ((= iteration 100)) (do ((row 0 (+ row 1))) ((= row 4)) (do ((col 0 (+ col 1))) ((= col 4)) (vector-set! c (+ (* row 4) col) (do ((k 0 (+ k 1)) (total 0 (+ total (* (vector-ref a (+ (* row 4) k)) (vector-ref b (+ (* k 4) col)))))) ((= k 4) total)))))) (do ((i 0 (+ i 1)) (total 0 (+ total (vector-ref c i)))) ((= i 16) total)))","harness":";; Benchmark runner for the lisp-hara comparison suite (GNU Guile).\n;; Contract mirrors lib/bench/luajit-hara/lua_runner.lua:\n;;   guile -s guile_runner.scm MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n;; Reads + evals the source on every call (matching hara's eval_native\n;; per-call semantics) and prints one JSON line:\n;;   {\"runtime\":\"guile\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n;;\n;; The rnrs import makes make-eqv-hashtable & co. visible to eval'd\n;; workload sources in the interaction environment.\n\n(import (rnrs base)\n        (rnrs hashtables)\n        (rnrs io ports)\n        (only (guile) internal-time-units-per-second))\n\n(define args (cdr (command-line)))\n\n(when (not (= (length args) 6))\n  (display \"guile_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\" (current-error-port))\n  (exit 2))\n\n(define mode (list-ref args 0))\n(define id (list-ref args 1))\n(define source-hex (list-ref args 2))\n(define expected (list-ref args 3))\n(define windows (string->number (list-ref args 4)))\n(define calls (string->number (list-ref args 5)))\n\n(unless (and windows calls)\n  (display (string-append id \": invalid windows/calls\\n\") (current-error-port))\n  (exit 2))\n\n(define (fail message)\n  (display (string-append id \": \" message \"\\n\") (current-error-port))\n  (exit 1))\n\n(define (hex-decode s)\n  (let* ((n (string-length s))\n         (out (make-string (quotient n 2))))\n    (do ((i 0 (+ i 2)))\n        ((>= i n) out)\n      (string-set! out (quotient i 2)\n                   (integer->char (string->number (substring s i (+ i 2)) 16))))))\n\n(define (clock-ns)\n  (round (* 1000000000 (/ (get-internal-run-time) internal-time-units-per-second))))\n\n(define source (hex-decode source-hex))\n(define form (read (open-input-string source)))\n(define prepare-started (clock-ns))\n(define prepared\n  (and (string=? mode \"prepared\")\n       (eval `(lambda () ,form) (interaction-environment))))\n(define prepare-ns (and prepared (- (clock-ns) prepare-started)))\n\n(define (->string v)\n  (call-with-string-output-port (lambda (p) (display v p))))\n\n(define (eval-once)\n  (let ((value (if prepared (prepared)\n                   (eval (read (open-input-string source)) (interaction-environment)))))\n    (unless (string=? (->string value) expected)\n      (fail (string-append \"expected \" expected \", got \" (->string value))))))\n\n(define started (clock-ns))\n(eval-once)\n(define first-ns (- (clock-ns) started))\n\n(define samples\n  (let loop ((w 0) (acc '()))\n    (if (>= w windows)\n        (reverse acc)\n        (let ((window-started (clock-ns)))\n          (do ((c 0 (+ c 1)))\n              ((>= c calls))\n            (eval-once))\n          (loop (+ w 1)\n                (cons (round (/ (- (clock-ns) window-started) calls)) acc))))))\n\n(display (string-append\n          \"{\\\"runtime\\\":\\\"guile\\\",\\\"workload\\\":\\\"\" id \"\\\",\\\"prepare_ns\\\":\"\n          (if prepare-ns (number->string (round prepare-ns)) \"null\") \",\\\"first_ns\\\":\"\n          (number->string (round first-ns)) \",\\\"samples_ns\\\":[\"\n          (let join ((rest samples))\n            (if (null? rest)\n                \"\"\n                (string-append (number->string (car rest))\n                               (if (null? (cdr rest)) \"\" (string-append \",\" (join (cdr rest)))))))\n          \"]}\\n\"))\n","harness_path":"suites/language/guile_runner.scm","prepare":{"description":"Read form and eval a zero-argument lambda","command":"guile -s guile_runner.scm prepared \u2026"}},"luajit":{"language":"Lua","source":"local a={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} local b={1,4,7,10,13,16,2,5,8,11,14,0,3,6,9,12} local c={} for iteration=1,100 do for row=0,3 do for col=0,3 do local total=0 for k=0,3 do total=total+a[row*4+k+1]*b[k*4+col+1] end c[row*4+col+1]=total end end end local total=0 for i=1,16 do total=total+c[i] end return total","harness":"#!/usr/bin/env luajit\n-- Benchmark runner for the luajit-hara comparison suite.\n-- Contract mirrors rust/src/bin/hara-runtime-benchmark.rs:\n--   luajit lua_runner.lua MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\n-- Loads the source once per call (load + call = parse + eval, matching\n-- hara's eval_native per-call semantics) and prints one JSON line:\n--   {\"runtime\":\"luajit\",\"workload\":\"ID\",\"first_ns\":N,\"samples_ns\":[...]}\n\nlocal args = { ... }\nif #args ~= 6 then\n  io.stderr:write(\"lua_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\\n\")\n  os.exit(2)\nend\n\nlocal mode = args[1]\nlocal id = args[2]\nlocal source_hex = args[3]\nlocal expected = args[4]\nlocal windows = tonumber(args[5])\nlocal calls = tonumber(args[6])\n\nif not windows or not calls then\n  io.stderr:write(id .. \": invalid windows/calls\\n\")\n  os.exit(2)\nend\n\nlocal function decode_hex(value)\n  if #value % 2 ~= 0 then return nil, \"invalid source hex\" end\n  local ok, result = pcall(function()\n    return (value:gsub(\"..\", function(byte)\n      return string.char(tonumber(byte, 16))\n    end))\n  end)\n  if ok then return result end\n  return nil, \"invalid source hex\"\nend\n\nlocal function fail(message)\n  io.stderr:write(id .. \": \" .. message .. \"\\n\")\n  os.exit(1)\nend\n\nlocal function clock_ns()\n  return os.clock() * 1e9\nend\n\nlocal source, err = decode_hex(source_hex)\nif not source then fail(err) end\nlocal prepared, prepared_err\nlocal prepare_started = clock_ns()\nif mode == \"prepared\" then prepared, prepared_err = load(source, \"workload\") end\nlocal prepare_ns = mode == \"prepared\" and math.floor(clock_ns() - prepare_started + 0.5) or nil\nif mode == \"prepared\" and not prepared then fail(prepared_err) end\n\nlocal function eval_once()\n  local chunk, load_err = prepared, nil\n  if not chunk then chunk, load_err = load(source, \"workload\") end\n  if not chunk then fail(load_err) end\n  local ok, value = pcall(chunk)\n  if not ok then fail(value) end\n  if tostring(value) ~= expected then\n    fail(\"expected \" .. expected .. \", got \" .. tostring(value))\n  end\nend\n\nlocal started = clock_ns()\neval_once()\nlocal first_ns = math.floor(clock_ns() - started + 0.5)\n\nlocal samples = {}\nfor _ = 1, windows do\n  local window_started = clock_ns()\n  for _ = 1, calls do\n    eval_once()\n  end\n  samples[#samples + 1] = math.floor((clock_ns() - window_started) / calls + 0.5)\nend\n\nlocal function json_escape(value)\n  return (value:gsub('\\\\', '\\\\\\\\'):gsub('\"', '\\\\\"'))\nend\n\nio.write('{\"runtime\":\"luajit\",\"workload\":\"' .. json_escape(id) ..\n  '\",\"prepare_ns\":' .. (prepare_ns or 'null') .. ',\"first_ns\":' .. first_ns .. ',\"samples_ns\":[' ..\n  table.concat(samples, \",\") .. \"]}\\n\")\n","harness_path":"adapters/luajit/lua_runner.lua","prepare":{"description":"Load source as a prepared Lua function","command":"luajit lua_runner.lua prepared \u2026"}},"bb":{"language":"Clojure","source":"(let [a (int-array (range 1 17)) b (int-array [1 4 7 10 13 16 2 5 8 11 14 0 3 6 9 12]) c (int-array 16)] (dotimes [_ 100] (dotimes [row 4] (dotimes [col 4] (aset-int c (+ (* row 4) col) (loop [k 0 total 0] (if (< k 4) (recur (inc k) (+ total (* (aget a (+ (* row 4) k)) (aget b (+ (* k 4) col))))) total)))))) (reduce + c))","harness":"#!/usr/bin/env bb\n\n(defn fail! [id message code]\n  (binding [*out* *err*] (println (str id \": \" message)))\n  (System/exit code))\n\n(defn hex-decode [value]\n  (apply str (map #(char (Integer/parseInt % 16)) (re-seq #\"..\" value))))\n\n(defn -main [& arguments]\n  (let [[mode id source-hex expected windows-text calls-text & extra] arguments]\n    (when (or extra (some nil? [mode id source-hex expected windows-text calls-text]))\n      (fail! \"bb_runner\" \"expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\" 2))\n    (let [windows (parse-long windows-text)\n          calls (parse-long calls-text)\n          source (hex-decode source-hex)\n          prepare-started (System/nanoTime)\n          prepared (when (= mode \"prepared\")\n                     (eval (read-string (str \"(fn [] \" source \")\"))))\n          prepare-ns (when prepared (- (System/nanoTime) prepare-started))\n          evaluate (fn []\n                     (let [value (if prepared\n                                   (prepared)\n                                   (eval (read-string source)))]\n                       (when-not (= (str value) expected)\n                         (fail! id (str \"expected \" expected \", got \" value) 1))))\n          started (System/nanoTime)]\n      (evaluate)\n      (let [first-ns (- (System/nanoTime) started)\n            samples (mapv (fn [_]\n                            (let [window-started (System/nanoTime)]\n                              (dotimes [_ calls] (evaluate))\n                              (quot (- (System/nanoTime) window-started) calls)))\n                          (range windows))]\n        (println (str \"{\\\"runtime\\\":\\\"bb\\\",\\\"workload\\\":\\\"\" id\n                      \"\\\",\\\"prepare_ns\\\":\" (or prepare-ns \"null\")\n                      \",\\\"first_ns\\\":\" first-ns\n                      \",\\\"samples_ns\\\":[\" (clojure.string/join \",\" samples) \"]}\"))))))\n\n(when (seq *command-line-args*)\n  (apply -main *command-line-args*))\n","harness_path":"suites/language/bb_runner.clj","prepare":{"description":"Read source and eval a zero-argument function","command":"bb bb_runner.clj prepared \u2026"}},"python":{"language":"Python","source":"def benchmark():\n    a=list(range(1,17)); b=[1,4,7,10,13,16,2,5,8,11,14,0,3,6,9,12]; c=[0]*16\n    for _ in range(100):\n        for row in range(4):\n            for col in range(4): c[row*4+col]=sum(a[row*4+k]*b[k*4+col] for k in range(4))\n    return sum(c)","harness":"#!/usr/bin/env python3\nimport json\nimport sys\nimport time\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"python_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    mode, workload, source_hex, expected, windows_text, calls_text = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    sys.setrecursionlimit(100_000)\n    windows, calls = int(windows_text), int(calls_text)\n    prepared = None\n    prepare_ns = None\n    if mode == \"prepared\":\n        prepare_started = time.perf_counter_ns()\n        scope = {}\n        exec(compile(source, workload, \"exec\"), scope)\n        prepared = scope[\"benchmark\"]\n        prepare_ns = time.perf_counter_ns() - prepare_started\n\n    def evaluate():\n        if prepared is None:\n            scope = {}\n            exec(compile(source, workload, \"exec\"), scope)\n            value = scope[\"benchmark\"]()\n        else:\n            value = prepared()\n        if str(value) != expected:\n            raise SystemExit(f\"{workload}: expected {expected}, got {value}\")\n\n    started = time.perf_counter_ns()\n    evaluate()\n    first_ns = time.perf_counter_ns() - started\n    samples = []\n    for _ in range(windows):\n        started = time.perf_counter_ns()\n        for _ in range(calls):\n            evaluate()\n        samples.append((time.perf_counter_ns() - started) // calls)\n    print(json.dumps({\"runtime\": \"python\", \"workload\": workload,\n                      \"prepare_ns\": prepare_ns, \"first_ns\": first_ns,\n                      \"samples_ns\": samples},\n                     separators=(\",\", \":\")))\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/python_runner.py","prepare":{"description":"compile(source, workload, 'exec'), then resolve benchmark","command":"python3 python_runner.py prepared \u2026"}},"c":{"language":"C","source":"int64_t benchmark(void) { volatile int64_t a[16],b[16]={1,4,7,10,13,16,2,5,8,11,14,0,3,6,9,12},c[16]={0}; for(int i=0;i<16;i++) a[i]=i+1+benchmark_seed; for(int iteration=0;iteration<100;iteration++) for(int row=0;row<4;row++) for(int col=0;col<4;col++) { int64_t total=0; for(int k=0;k<4;k++) total+=a[row*4+k]*b[k*4+col]; c[row*4+col]=total; } int64_t total=0; for(int i=0;i<16;i++) total+=c[i]; return total; }","harness":"#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = r'''#include <inttypes.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\nvolatile int64_t benchmark_seed = 0;\n{source}\nstatic uint64_t now_ns(void) {{\n  struct timespec value;\n  clock_gettime(CLOCK_MONOTONIC_RAW, &value);\n  return (uint64_t)value.tv_sec * 1000000000ULL + (uint64_t)value.tv_nsec;\n}}\nint main(int argc, char **argv) {{\n  const char *id = argv[1];\n  int64_t expected = strtoll(argv[2], NULL, 10);\n  int windows = atoi(argv[3]), calls = atoi(argv[4]);\n  uint64_t prepare_ns = strtoull(argv[5], NULL, 10);\n  uint64_t started = now_ns();\n  int64_t value = benchmark();\n  uint64_t first = now_ns() - started;\n  if (value != expected) {{ fprintf(stderr, \"%s: expected %\" PRId64 \", got %\" PRId64 \"\\n\", id, expected, value); return 1; }}\n  printf(\"{{\\\"runtime\\\":\\\"c\\\",\\\"workload\\\":\\\"%s\\\",\\\"prepare_ns\\\":%\" PRIu64 \",\\\"first_ns\\\":%\" PRIu64 \",\\\"samples_ns\\\":[\", id, prepare_ns, first);\n  for (int window = 0; window < windows; window++) {{\n    started = now_ns();\n    for (int call = 0; call < calls; call++) value = benchmark();\n    uint64_t sample = (now_ns() - started) / (uint64_t)calls;\n    if (value != expected) return 1;\n    printf(\"%s%\" PRIu64, window ? \",\" : \"\", sample);\n  }}\n  puts(\"]}}\");\n  return 0;\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"c_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    with tempfile.TemporaryDirectory(prefix=\"hara-c-bench-\") as directory:\n        root = Path(directory)\n        source_path, binary = root / \"benchmark.c\", root / \"benchmark\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([\"cc\", \"-O3\", \"-std=c11\", str(source_path), \"-o\", str(binary)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([str(binary), workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/c_runner.py","prepare":{"description":"Generate translation unit and compile with cc -O3","command":"cc -O3 -std=c11 benchmark.c -o benchmark"}},"java":{"language":"Java","source":"static long benchmark() { long[] a=new long[16],b={1,4,7,10,13,16,2,5,8,11,14,0,3,6,9,12},c=new long[16]; for(int i=0;i<16;i++) a[i]=i+1; for(int iteration=0;iteration<100;iteration++) for(int row=0;row<4;row++) for(int col=0;col<4;col++) { long total=0; for(int k=0;k<4;k++) total+=a[row*4+k]*b[k*4+col]; c[row*4+col]=total; } long total=0; for(long value:c) total+=value; return total; }","harness":"#!/usr/bin/env python3\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\nimport time\nfrom pathlib import Path\n\n\nTEMPLATE = '''public final class HaraAlgorithmBenchmark {{\n  {source}\n  public static void main(String[] args) {{\n    String id = args[0];\n    long expected = Long.parseLong(args[1]);\n    int windows = Integer.parseInt(args[2]), calls = Integer.parseInt(args[3]);\n    long prepareNs = Long.parseLong(args[4]);\n    long started = System.nanoTime();\n    long value = benchmark();\n    long first = System.nanoTime() - started;\n    if (value != expected) throw new AssertionError(id + \": expected \" + expected + \", got \" + value);\n    StringBuilder out = new StringBuilder(\"{{\\\\\\\"runtime\\\\\\\":\\\\\\\"java\\\\\\\",\\\\\\\"workload\\\\\\\":\\\\\\\"\").append(id)\n      .append(\"\\\\\\\",\\\\\\\"prepare_ns\\\\\\\":\").append(prepareNs).append(\",\\\\\\\"first_ns\\\\\\\":\").append(first).append(\",\\\\\\\"samples_ns\\\\\\\":[\");\n    for (int window = 0; window < windows; window++) {{\n      started = System.nanoTime();\n      for (int call = 0; call < calls; call++) value = benchmark();\n      long sample = (System.nanoTime() - started) / calls;\n      if (value != expected) throw new AssertionError(id + \": checksum changed\");\n      if (window != 0) out.append(',');\n      out.append(sample);\n    }}\n    System.out.println(out.append(\"]}}\").toString());\n  }}\n}}\n'''\n\n\ndef main():\n    if len(sys.argv) != 7:\n        raise SystemExit(\"java_runner expects MODE ID SOURCE_HEX EXPECTED WINDOWS CALLS\")\n    _, workload, source_hex, expected, windows, calls = sys.argv[1:]\n    source = bytes.fromhex(source_hex).decode()\n    java_home = os.environ.get(\"HARA_BENCH_JAVA_HOME\")\n    homebrew = Path(\"/opt/homebrew/opt/openjdk@21/bin\")\n    if java_home:\n        javac, java = str(Path(java_home) / \"bin/javac\"), str(Path(java_home) / \"bin/java\")\n    elif homebrew.is_dir():\n        javac, java = str(homebrew / \"javac\"), str(homebrew / \"java\")\n    else:\n        javac, java = shutil.which(\"javac\"), shutil.which(\"java\")\n    if not javac or not java:\n        raise SystemExit(\"java and javac must be on PATH or HARA_BENCH_JAVA_HOME must be set\")\n    with tempfile.TemporaryDirectory(prefix=\"hara-java-bench-\") as directory:\n        root = Path(directory)\n        source_path = root / \"HaraAlgorithmBenchmark.java\"\n        prepare_started = time.perf_counter_ns()\n        source_path.write_text(TEMPLATE.format(source=source))\n        subprocess.run([javac, \"-g:none\", str(source_path)], check=True)\n        prepare_ns = time.perf_counter_ns() - prepare_started\n        completed = subprocess.run([java, \"-cp\", str(root), \"HaraAlgorithmBenchmark\",\n                                    workload, expected, windows, calls, str(prepare_ns)])\n        raise SystemExit(completed.returncode)\n\n\nif __name__ == \"__main__\":\n    main()\n","harness_path":"suites/language/java_runner.py","prepare":{"description":"Generate class and compile without debug metadata","command":"javac -g:none HaraAlgorithmBenchmark.java"}}}}]}
