#!/usr/bin/env python3
"""Cold-start cost in a fresh process: import, engine construction, first evaluate().

Run once per fresh interpreter (e.g. in a shell loop) so nothing is warm.
"""
import time

t_import0 = time.perf_counter_ns()
from helixor_runtime import HelixorEngine  # noqa: E402
t_import1 = time.perf_counter_ns()

from _common import PAYLOADS, environment  # noqa: E402


def main() -> None:
    t0 = time.perf_counter_ns()
    engine = HelixorEngine()
    t1 = time.perf_counter_ns()
    engine.evaluate(PAYLOADS[1])
    t2 = time.perf_counter_ns()
    engine.evaluate(PAYLOADS[1])
    t3 = time.perf_counter_ns()
    print(environment())
    print(
        f"import={(t_import1 - t_import0) / 1e6:.2f}ms construct={(t1 - t0) / 1e6:.2f}ms "
        f"first_evaluate={(t2 - t1) / 1e3:.1f}us second_evaluate={(t3 - t2) / 1e3:.1f}us"
    )


if __name__ == "__main__":
    main()
