from __future__ import annotations import json import platform import time from pathlib import Path ROOT = Path(__file__).resolve().parent from telemetry import ( RobustPCADetector, causal_window_features, generate_telemetry_run, ) def main() -> None: artifact = json.loads( (ROOT / "model.json").read_text() ) detector = RobustPCADetector.from_dict(artifact) features, _ = causal_window_features(generate_telemetry_run(999).values) for _ in range(100): detector.score_features(features) repetitions = 2000 started = time.perf_counter_ns() for _ in range(repetitions): detector.score_features(features) elapsed_ns = time.perf_counter_ns() - started windows = len(features) * repetitions print( json.dumps( { "runtime": "NumPy CPU", "python": platform.python_version(), "machine": platform.machine(), "processor": platform.processor() or "not reported", "windows": windows, "elapsed_seconds": round(elapsed_ns / 1e9, 6), "microseconds_per_window": round(elapsed_ns / windows / 1e3, 6), "warning": "Local microbenchmark; rerun on the intended edge target.", }, indent=2, ) ) if __name__ == "__main__": main()