/ examples / performance / run_all_examples.py
run_all_examples.py
 1  #!/usr/bin/env python3
 2  """
 3  Runner for all performance examples.
 4  
 5  Usage:
 6      # Run without real API (mock only)
 7      python run_all_examples.py
 8      
 9      # Run with real API
10      RUN_REAL_KEY_TESTS=1 OPENAI_API_KEY=your-key python run_all_examples.py
11  """
12  import os
13  import sys
14  import subprocess
15  
16  
17  def run_example(name, script_path):
18      """Run an example script and report results."""
19      print(f"\n{'=' * 60}")
20      print(f"Running: {name}")
21      print("=" * 60)
22      
23      result = subprocess.run(
24          [sys.executable, script_path],
25          capture_output=True,
26          text=True,
27          env=os.environ.copy()
28      )
29      
30      print(result.stdout)
31      if result.stderr:
32          print(f"STDERR: {result.stderr}")
33      
34      return result.returncode == 0
35  
36  
37  def main():
38      """Run all performance examples."""
39      print("PraisonAI Agents - Performance Examples Runner")
40      print("=" * 60)
41      
42      # Check environment
43      real_tests = os.environ.get("RUN_REAL_KEY_TESTS")
44      has_openai = bool(os.environ.get("OPENAI_API_KEY"))
45      
46      print(f"RUN_REAL_KEY_TESTS: {real_tests or 'not set'}")
47      print(f"OPENAI_API_KEY: {'set' if has_openai else 'not set'}")
48      
49      # Get script directory
50      script_dir = os.path.dirname(os.path.abspath(__file__))
51      
52      # Define examples
53      examples = [
54          ("Lazy Imports", os.path.join(script_dir, "lazy_imports_example.py")),
55          ("Lite Agent", os.path.join(script_dir, "lite_agent_example.py")),
56          ("Thread Safety", os.path.join(script_dir, "thread_safety_example.py")),
57      ]
58      
59      # Run examples
60      results = []
61      for name, path in examples:
62          if os.path.exists(path):
63              success = run_example(name, path)
64              results.append((name, success))
65          else:
66              print(f"Skipping {name}: {path} not found")
67              results.append((name, None))
68      
69      # Summary
70      print("\n" + "=" * 60)
71      print("Summary")
72      print("=" * 60)
73      
74      passed = 0
75      failed = 0
76      skipped = 0
77      
78      for name, success in results:
79          if success is None:
80              status = "SKIPPED"
81              skipped += 1
82          elif success:
83              status = "PASS"
84              passed += 1
85          else:
86              status = "FAIL"
87              failed += 1
88          print(f"  {name}: {status}")
89      
90      print(f"\nTotal: {passed} passed, {failed} failed, {skipped} skipped")
91      
92      return 0 if failed == 0 else 1
93  
94  
95  if __name__ == "__main__":
96      sys.exit(main())