@@ -148,7 +148,8 @@ async def benchmark_security_audit(cache) -> BenchmarkResult:
148148 test_dir = Path ("/tmp/empathy_test_audit" )
149149 test_dir .mkdir (exist_ok = True )
150150 test_file = test_dir / "app.py"
151- test_file .write_text ("""
151+ test_file .write_text (
152+ """
152153import os
153154import subprocess
154155
@@ -165,7 +166,8 @@ def process_data(data):
165166 # SQL injection risk
166167 query = f"SELECT * FROM users WHERE name = '{data}'"
167168 return execute_query(query)
168- """ )
169+ """
170+ )
169171
170172 workflow = SecurityAuditWorkflow (cache = cache , enable_cache = True )
171173
@@ -211,7 +213,8 @@ async def benchmark_bug_predict(cache) -> BenchmarkResult:
211213 test_dir = Path ("/tmp/empathy_test_bugs" )
212214 test_dir .mkdir (exist_ok = True )
213215 test_file = test_dir / "buggy.py"
214- test_file .write_text ("""
216+ test_file .write_text (
217+ """
215218def divide_numbers(a, b):
216219 # Missing zero check
217220 return a / b
@@ -231,7 +234,8 @@ def broad_exception():
231234 except:
232235 # Bare except
233236 pass
234- """ )
237+ """
238+ )
235239
236240 workflow = BugPredictionWorkflow (cache = cache , enable_cache = True )
237241
@@ -277,7 +281,8 @@ async def benchmark_refactor_plan(cache) -> BenchmarkResult:
277281 test_dir = Path ("/tmp/empathy_test_refactor" )
278282 test_dir .mkdir (exist_ok = True )
279283 test_file = test_dir / "messy.py"
280- test_file .write_text ("""
284+ test_file .write_text (
285+ """
281286class DataProcessor:
282287 def process(self, data):
283288 # Long method with multiple responsibilities
@@ -300,7 +305,8 @@ def process(self, data):
300305 valid_results.append(r)
301306
302307 return valid_results
303- """ )
308+ """
309+ )
304310
305311 workflow = RefactorPlanWorkflow (cache = cache , enable_cache = True )
306312
@@ -397,6 +403,7 @@ async def benchmark_health_check(cache) -> BenchmarkResult:
397403 finally :
398404 # Cleanup
399405 import shutil
406+
400407 shutil .rmtree (test_dir , ignore_errors = True )
401408
402409 return result
@@ -410,7 +417,8 @@ async def benchmark_test_generation(cache) -> BenchmarkResult:
410417 test_dir = Path ("/tmp/empathy_testgen_bench" )
411418 test_dir .mkdir (exist_ok = True )
412419 test_file = test_dir / "calculator.py"
413- test_file .write_text ("""
420+ test_file .write_text (
421+ """
414422def add(a, b):
415423 return a + b
416424
@@ -419,7 +427,8 @@ def subtract(a, b):
419427
420428def multiply(a, b):
421429 return a * b
422- """ )
430+ """
431+ )
423432
424433 workflow = TestGenerationWorkflow (cache = cache , enable_cache = True )
425434
@@ -452,6 +461,7 @@ def multiply(a, b):
452461 finally :
453462 # Cleanup
454463 import shutil
464+
455465 shutil .rmtree (test_dir , ignore_errors = True )
456466
457467 return result
@@ -465,7 +475,8 @@ async def benchmark_perf_audit(cache) -> BenchmarkResult:
465475 test_dir = Path ("/tmp/empathy_perfaudit_bench" )
466476 test_dir .mkdir (exist_ok = True )
467477 test_file = test_dir / "slow_code.py"
468- test_file .write_text ("""
478+ test_file .write_text (
479+ """
469480import time
470481
471482def slow_function():
@@ -482,7 +493,8 @@ def repeated_calls():
482493 for i in range(100):
483494 data.append(slow_function())
484495 return data
485- """ )
496+ """
497+ )
486498
487499 workflow = PerformanceAuditWorkflow (cache = cache , enable_cache = True )
488500
@@ -515,6 +527,7 @@ def repeated_calls():
515527 finally :
516528 # Cleanup
517529 import shutil
530+
518531 shutil .rmtree (test_dir , ignore_errors = True )
519532
520533 return result
@@ -528,12 +541,14 @@ async def benchmark_dependency_check(cache) -> BenchmarkResult:
528541 test_dir = Path ("/tmp/empathy_depcheck_bench" )
529542 test_dir .mkdir (exist_ok = True )
530543 req_file = test_dir / "requirements.txt"
531- req_file .write_text ("""
544+ req_file .write_text (
545+ """
532546requests==2.25.0
533547numpy==1.19.0
534548pandas==1.1.0
535549flask==1.1.2
536- """ )
550+ """
551+ )
537552
538553 workflow = DependencyCheckWorkflow (cache = cache , enable_cache = True )
539554
@@ -566,6 +581,7 @@ async def benchmark_dependency_check(cache) -> BenchmarkResult:
566581 finally :
567582 # Cleanup
568583 import shutil
584+
569585 shutil .rmtree (test_dir , ignore_errors = True )
570586
571587 return result
@@ -592,7 +608,9 @@ def calculate_fibonacci(n: int) -> int:
592608 # Run 1 (cold cache - should be 0% hit rate)
593609 print (" ▶ Run 1 (cold cache)..." )
594610 start = time .time ()
595- r1 = await workflow .execute (source_code = test_code , doc_type = "api_reference" , audience = "developers" )
611+ r1 = await workflow .execute (
612+ source_code = test_code , doc_type = "api_reference" , audience = "developers"
613+ )
596614 result .run1_time = time .time () - start
597615 result .run1_success = r1 .success
598616 result .run1_cost = r1 .cost_report .total_cost
@@ -602,7 +620,9 @@ def calculate_fibonacci(n: int) -> int:
602620 # Run 2 (warm cache - should be ~100% hit rate)
603621 print (" ▶ Run 2 (warm cache)..." )
604622 start = time .time ()
605- r2 = await workflow .execute (source_code = test_code , doc_type = "api_reference" , audience = "developers" )
623+ r2 = await workflow .execute (
624+ source_code = test_code , doc_type = "api_reference" , audience = "developers"
625+ )
606626 result .run2_time = time .time () - start
607627 result .run2_success = r2 .success
608628 result .run2_cost = r2 .cost_report .total_cost
@@ -661,6 +681,7 @@ async def benchmark_release_prep(cache) -> BenchmarkResult:
661681 finally :
662682 # Cleanup
663683 import shutil
684+
664685 shutil .rmtree (test_dir , ignore_errors = True )
665686
666687 return result
@@ -674,7 +695,7 @@ async def benchmark_research_synthesis(cache) -> BenchmarkResult:
674695 sources = [
675696 "Machine learning is a subset of AI that enables systems to learn from data." ,
676697 "Deep learning uses neural networks with multiple layers." ,
677- "Supervised learning requires labeled training data."
698+ "Supervised learning requires labeled training data." ,
678699 ]
679700 question = "What is the difference between ML and deep learning?"
680701
@@ -720,7 +741,8 @@ async def benchmark_keyboard_shortcuts(cache) -> BenchmarkResult:
720741
721742 # Create a simple package.json with commands
722743 package_json = test_dir / "package.json"
723- package_json .write_text ("""{
744+ package_json .write_text (
745+ """{
724746 "name": "test-extension",
725747 "contributes": {
726748 "commands": [
@@ -730,7 +752,8 @@ async def benchmark_keyboard_shortcuts(cache) -> BenchmarkResult:
730752 {"command": "extension.debug", "title": "Start Debugging"}
731753 ]
732754 }
733- }""" )
755+ }"""
756+ )
734757
735758 workflow = KeyboardShortcutWorkflow (cache = cache , enable_cache = True )
736759
@@ -763,12 +786,15 @@ async def benchmark_keyboard_shortcuts(cache) -> BenchmarkResult:
763786 finally :
764787 # Cleanup
765788 import shutil
789+
766790 shutil .rmtree (test_dir , ignore_errors = True )
767791
768792 return result
769793
770794
771- def generate_report (results : list [BenchmarkResult ], output_file : str = "CACHING_BENCHMARK_REPORT.md" ):
795+ def generate_report (
796+ results : list [BenchmarkResult ], output_file : str = "CACHING_BENCHMARK_REPORT.md"
797+ ):
772798 """Generate markdown report from benchmark results."""
773799 import sys
774800
@@ -787,9 +813,7 @@ def generate_report(results: list[BenchmarkResult], output_file: str = "CACHING_
787813 )
788814
789815 # Safe percentage calculation
790- savings_percent = (
791- (total_savings / total_run1_cost * 100 ) if total_run1_cost > 0 else 0.0
792- )
816+ savings_percent = (total_savings / total_run1_cost * 100 ) if total_run1_cost > 0 else 0.0
793817
794818 # Get Python version
795819 python_version = sys .version .split ()[0 ]
@@ -865,7 +889,9 @@ def generate_report(results: list[BenchmarkResult], output_file: str = "CACHING_
865889 # Analyze results
866890 high_hit_rate = [r for r in results if r .run2_hit_rate >= 50 ]
867891 if high_hit_rate :
868- report += f"- **{ len (high_hit_rate )} workflows** achieved ≥50% cache hit rate on second run\n "
892+ report += (
893+ f"- **{ len (high_hit_rate )} workflows** achieved ≥50% cache hit rate on second run\n "
894+ )
869895
870896 if successful_results :
871897 max_savings = max (successful_results , key = lambda r : r .cache_savings )
@@ -971,7 +997,9 @@ async def main():
971997 print (f" ❌ Error: { result .error } " )
972998 else :
973999 print (f" ✅ Run 1: ${ result .run1_cost :.6f} , { result .run1_time :.2f} s" )
974- print (f" ✅ Run 2: ${ result .run2_cost :.6f} , { result .run2_time :.2f} s ({ result .run2_hit_rate :.1f} % hit rate)" )
1000+ print (
1001+ f" ✅ Run 2: ${ result .run2_cost :.6f} , { result .run2_time :.2f} s ({ result .run2_hit_rate :.1f} % hit rate)"
1002+ )
9751003 print (f" 💰 Savings: ${ result .cache_savings :.6f} " )
9761004 print ()
9771005
0 commit comments