import time
import blake3
from agdr_phoenix import AKIEngine, PPPTriplet, HumanDeltaChain
def benchmark_rust_path(iterations=100000):
engine = AKIEngine(':memory:')
ppp = PPPTriplet(
provenance='Benchmark Test',
place='Test Environment',
purpose='Latency Measurement'
)
hdc = HumanDeltaChain(
agent_decision_ref='bench_001',
resolved=True,
terminal_node='autonomous'
)
for _ in range(10_000):
engine.capture(ppp, hdc, 'warmup', 0.95, 0.5)
start_time = time.perf_counter()
for _ in range(iterations):
engine.capture(ppp, hdc, 'Benchmark capture speed test', 0.95, 0.5)
end_time = time.perf_counter()
total_time = end_time - start_time
avg_time_ns = (total_time / iterations) * 1_000_000_000
print('--- Rust AKI Hot Path Benchmark ---')
print(f'Total time for {iterations} captures: {total_time:.4f} seconds')
print(f'Average capture latency: {avg_time_ns:.2f} ns')
print(f'Throughput: {iterations/total_time:,.0f} AKI/sec')
if __name__ == '__main__':
benchmark_rust_path()