/ examples / benchmark_example.py
benchmark_example.py
 1  import json
 2  import time
 3  
 4  
 5  def main() -> None:
 6      # Replace this with your real benchmark invocation and measurements.
 7      start = time.perf_counter()
 8      time.sleep(0.05)
 9      _ = sum(i * i for i in range(20000))
10      elapsed = (time.perf_counter() - start) * 1_000_000
11  
12      metrics = {
13          "total_us": {
14              "before": 1_234_567,
15              "after": int(elapsed),
16              "delta_pct": round(((elapsed - 1_234_567) / 1_234_567) * 100, 2),
17          },
18          "memory_mb": {
19              "before": 256,
20              "after": 180,
21              "delta_pct": -29.69,
22          },
23      }
24  
25      print(json.dumps({"metrics": metrics}))
26  
27  
28  if __name__ == "__main__":
29      main()