#!/usr/bin/env python3
"""End-to-end wall clock per HelixorEngine.evaluate() call.

Times the full public call (license check, extraction, invariants, remedy,
receipt hashing, result-model construction) with perf_counter_ns, which the
engine's own latency_us field excludes in part. 100 warm-up calls, then 10,000
timed calls cycling over five payloads.
"""
import time

from helixor_runtime import HelixorEngine

from _common import PAYLOADS, environment, summarize

WARMUP = 100
N = 10_000


def main() -> None:
    print(environment())
    engine = HelixorEngine()
    for i in range(WARMUP):
        engine.evaluate(PAYLOADS[i % len(PAYLOADS)])

    wall_ns: list[int] = []
    reported_us: list[float] = []
    clock = time.perf_counter_ns
    for i in range(N):
        payload = PAYLOADS[i % len(PAYLOADS)]
        t0 = clock()
        res = engine.evaluate(payload)
        wall_ns.append(clock() - t0)
        reported_us.append(res.latency_us)

    summarize("evaluate() end-to-end wall clock", wall_ns)
    summarize("evaluate() engine-reported latency_us", [int(u * 1000) for u in reported_us])


if __name__ == "__main__":
    main()
