"""CPU toy-model timing only: not GPU, quantization or production capacity evidence."""
from pathlib import Path
from statistics import median
from time import perf_counter
import numpy as np
import onnxruntime as ort
options = ort.SessionOptions()
options.intra_op_num_threads = 1
start = perf_counter()
session = ort.InferenceSession(str(Path(__file__).with_name('linear.onnx')), sess_options=options, providers=['CPUExecutionProvider'])
load_ms = (perf_counter()-start)*1000
inputs = {'x':np.array([[1,2,3]],np.float32)}
for _ in range(10):
    session.run(['y'], inputs)
times = []
for _ in range(100):
    start = perf_counter()
    output = session.run(['y'], inputs)[0]
    times.append((perf_counter()-start)*1000)
np.testing.assert_allclose(output, [[3,5,7]])
p95 = sorted(times)[94]  # nearest-rank 95th percentile of n=100.
assert len(times)==100 and all(t>=0 for t in times)
print(f'PASS: CPU, ORT {ort.__version__}, shape [1,3], intra_op=1, warmup=10, n=100')
print(f'load_ms={load_ms:.3f}, median_ms={median(times):.4f}, p95_ms={p95:.4f}; timings vary by machine')
