HNTAI / scripts /test_benchmark.py
sachinchandrankallar's picture
bench mark
188ec8d
import time
import os
import sys
# Ensure src is in path
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(current_dir)
sys.path.insert(0, os.path.join(project_root, "services", "ai-service", "src"))
from ai_med_extract.utils.benchmark import BenchmarkContext, BenchmarkLogger, benchmark_activity
@benchmark_activity("test_sleep_activity")
def test_sleep():
print("Testing sleep for 1 second...")
time.sleep(1.0)
print("Done sleeping.")
def main():
print(f"Running benchmark test in {os.getcwd()}")
# Test context manager directly
print("Testing Context Manager...")
with BenchmarkContext("test_context_block", meta={"type": "test"}) as bm:
time.sleep(0.5)
bm.meta["extra_info"] = "worked"
# Test decorator
print("Testing Decorator...")
test_sleep()
print("Test complete. Checking logs...")
log_file = "logs/benchmark.jsonl"
if os.path.exists(log_file):
print(f"Log file exists: {log_file}")
with open(log_file, "r") as f:
print("--- Log Content ---")
print(f.read())
print("-------------------")
else:
print(f"Log file NOT found at {log_file}")
if __name__ == "__main__":
main()