Skip to content

Commit 9d3cb28

Browse files
committed
implemente copilot suggestions
1 parent 4d2453e commit 9d3cb28

2 files changed

Lines changed: 41 additions & 41 deletions

File tree

tests/test_dask_benchmarks.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def create_dask_clients() -> List[Tuple[str, Optional[Client]]]:
186186
threaded_client = Client(threaded_cluster)
187187
clients.append(("threaded", threaded_client))
188188
except Exception as e:
189-
print(f"Failed to create threaded client: {e}")
189+
logging.info(f"Failed to create threaded client: {e}")
190190

191191
# Process-based client (if not Windows or if requested)
192192
if platform.system() != "Windows":
@@ -201,7 +201,7 @@ def create_dask_clients() -> List[Tuple[str, Optional[Client]]]:
201201
process_client = Client(process_cluster)
202202
clients.append(("processes", process_client))
203203
except Exception as e:
204-
print(f"Failed to create process client: {e}")
204+
logging.info(f"Failed to create process client: {e}")
205205

206206
return clients
207207

@@ -314,7 +314,7 @@ def mock_tax_computation(self, data: pd.DataFrame, year: str) -> Dict:
314314
}
315315

316316
# Add some CPU time to simulate real computation
317-
time.sleep(0.01) # 10ms per task
317+
_ = np.linalg.svd(np.random.rand(50, 50))
318318

319319
return result
320320

@@ -413,7 +413,7 @@ def test_small_dataset_multiprocessing(self, small_tax_data):
413413
)
414414
save_benchmark_result(result)
415415
assert result.success, f"Benchmark failed: {result.error_message}"
416-
print(
416+
logging.info(
417417
f"Small dataset multiprocessing: {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
418418
)
419419

@@ -425,7 +425,7 @@ def test_small_dataset_threaded(self, small_tax_data):
425425
)
426426
save_benchmark_result(result)
427427
assert result.success, f"Benchmark failed: {result.error_message}"
428-
print(
428+
logging.info(
429429
f"Small dataset threaded: {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
430430
)
431431

@@ -447,7 +447,7 @@ def test_medium_dataset_comparison(self, medium_tax_data):
447447
)
448448
results.append(result)
449449
save_benchmark_result(result)
450-
print(
450+
logging.info(
451451
f"Medium {scheduler}: {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
452452
)
453453

@@ -475,7 +475,7 @@ def test_distributed_clients_comparison(self, medium_tax_data):
475475
)
476476
results.append(result)
477477
save_benchmark_result(result)
478-
print(
478+
logging.info(
479479
f"Distributed {client_name}: {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
480480
)
481481

@@ -517,7 +517,7 @@ def test_memory_scaling(self, small_tax_data, medium_tax_data):
517517
if result.data_size_mb > 0
518518
else 0
519519
)
520-
print(
520+
logging.info(
521521
f"Memory scaling {name}: {result.data_size_mb:.1f}MB data -> {result.peak_memory_mb:.1f}MB peak (ratio: {memory_per_mb:.2f})"
522522
)
523523

@@ -551,7 +551,7 @@ def test_worker_scaling(self, medium_tax_data):
551551
)
552552
results.append(result)
553553
save_benchmark_result(result)
554-
print(f"Worker scaling {num_workers}: {result.compute_time:.3f}s")
554+
logging.info(f"Worker scaling {num_workers}: {result.compute_time:.3f}s")
555555

556556
# Performance should improve or stay similar with more workers
557557
if all(r.success for r in results):
@@ -560,7 +560,7 @@ def test_worker_scaling(self, medium_tax_data):
560560

561561
# Allow some overhead, but expect some improvement
562562
speedup = single_worker_time / max_worker_time
563-
print(f"Speedup with {max_workers} workers: {speedup:.2f}x")
563+
logging.info(f"Speedup with {max_workers} workers: {speedup:.2f}x")
564564

565565
# Should be at least 1.2x speedup with multiple workers (conservative)
566566
if max_workers > 1:
@@ -583,7 +583,7 @@ def test_large_dataset_stress(self, large_tax_data):
583583
)
584584
save_benchmark_result(result)
585585

586-
print(
586+
logging.info(
587587
f"Large dataset stress ({scheduler}): {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
588588
)
589589

@@ -613,7 +613,7 @@ def load_benchmark_results() -> List[BenchmarkResult]:
613613
result = BenchmarkResult(**data)
614614
results.append(result)
615615
except Exception as e:
616-
print(f"Failed to load {filename}: {e}")
616+
logging.info(f"Failed to load {filename}: {e}")
617617

618618
return results
619619

@@ -622,12 +622,12 @@ def generate_benchmark_report():
622622
"""Generate a summary report of all benchmark results."""
623623
results = load_benchmark_results()
624624
if not results:
625-
print("No benchmark results found.")
625+
logging.info("No benchmark results found.")
626626
return
627627

628-
print("\n" + "=" * 80)
629-
print("DASK PERFORMANCE BENCHMARK REPORT")
630-
print("=" * 80)
628+
logging.info("\n" + "=" * 80)
629+
logging.info("DASK PERFORMANCE BENCHMARK REPORT")
630+
logging.info("=" * 80)
631631

632632
# Group by platform and scheduler
633633
by_config = {}
@@ -638,8 +638,8 @@ def generate_benchmark_report():
638638
by_config[key].append(result)
639639

640640
for (platform, scheduler), config_results in by_config.items():
641-
print(f"\n{platform} - {scheduler}:")
642-
print("-" * 40)
641+
logging.info(f"\n{platform} - {scheduler}:")
642+
logging.info("-" * 40)
643643

644644
successful = [r for r in config_results if r.success]
645645
failed = [r for r in config_results if not r.success]
@@ -651,14 +651,14 @@ def generate_benchmark_report():
651651
avg_memory = sum(r.peak_memory_mb for r in successful) / len(
652652
successful
653653
)
654-
print(f" Successful tests: {len(successful)}")
655-
print(f" Average time: {avg_time:.3f}s")
656-
print(f" Average peak memory: {avg_memory:.1f}MB")
654+
logging.info(f" Successful tests: {len(successful)}")
655+
logging.info(f" Average time: {avg_time:.3f}s")
656+
logging.info(f" Average peak memory: {avg_memory:.1f}MB")
657657

658658
if failed:
659-
print(f" Failed tests: {len(failed)}")
659+
logging.info(f" Failed tests: {len(failed)}")
660660
for failure in failed[:3]: # Show first 3 failures
661-
print(f" {failure.test_name}: {failure.error_message}")
661+
logging.info(f" {failure.test_name}: {failure.error_message}")
662662

663663

664664
if __name__ == "__main__":

tests/test_real_txfunc_benchmarks.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import shutil
1515
from pathlib import Path
1616
import json
17-
17+
import logging
1818
import pytest
1919
import numpy as np
2020
import pandas as pd
@@ -183,7 +183,7 @@ def create_realistic_micro_data(
183183
data = data[valid_mask].reset_index(drop=True)
184184
micro_data[str(year)] = data
185185

186-
print(f"Generated {len(data)} valid tax records for year {year}")
186+
logging.info(f"Generated {len(data)} valid tax records for year {year}")
187187

188188
return micro_data
189189

@@ -317,7 +317,7 @@ def test_real_small_no_client(self, small_real_data):
317317
)
318318
save_benchmark_result(result)
319319

320-
print(
320+
logging.info(
321321
f"Real small (no client): {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
322322
)
323323
assert result.success, f"Real benchmark failed: {result.error_message}"
@@ -345,7 +345,7 @@ def test_real_small_threaded_client(self, small_real_data):
345345
)
346346
save_benchmark_result(result)
347347

348-
print(
348+
logging.info(
349349
f"Real small (threaded): {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
350350
)
351351
assert (
@@ -383,7 +383,7 @@ def test_real_small_process_client(self, small_real_data):
383383
)
384384
save_benchmark_result(result)
385385

386-
print(
386+
logging.info(
387387
f"Real small (processes): {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB peak"
388388
)
389389
assert (
@@ -416,7 +416,7 @@ def test_real_medium_comparison(self, medium_real_data):
416416
threaded_client = Client(threaded_cluster)
417417
configs.append(("threaded", threaded_client))
418418
except Exception as e:
419-
print(f"Failed to create threaded client: {e}")
419+
logging.info(f"Failed to create threaded client: {e}")
420420

421421
# Process client (skip on Windows due to known issues)
422422
if platform.system() != "Windows":
@@ -431,7 +431,7 @@ def test_real_medium_comparison(self, medium_real_data):
431431
process_client = Client(process_cluster)
432432
configs.append(("processes", process_client))
433433
except Exception as e:
434-
print(f"Failed to create process client: {e}")
434+
logging.info(f"Failed to create process client: {e}")
435435

436436
results = []
437437

@@ -446,7 +446,7 @@ def test_real_medium_comparison(self, medium_real_data):
446446
results.append(result)
447447
save_benchmark_result(result)
448448

449-
print(
449+
logging.info(
450450
f"Real medium ({config_name}): {result.compute_time:.3f}s, {result.peak_memory_mb:.1f}MB"
451451
)
452452

@@ -470,7 +470,7 @@ def test_real_medium_comparison(self, medium_real_data):
470470
# Report performance comparison
471471
if len(successful_results) > 1:
472472
fastest = min(successful_results, key=lambda x: x.compute_time)
473-
print(
473+
logging.info(
474474
f"Fastest configuration: {fastest.scheduler} ({fastest.compute_time:.3f}s)"
475475
)
476476

@@ -500,7 +500,7 @@ def test_real_memory_efficiency(self, small_real_data, medium_real_data):
500500
if result.data_size_mb > 0
501501
else float("inf")
502502
)
503-
print(
503+
logging.info(
504504
f"Real memory {name}: {result.data_size_mb:.1f}MB data -> {result.peak_memory_mb:.1f}MB peak (efficiency: {memory_efficiency:.2f})"
505505
)
506506

@@ -513,7 +513,7 @@ def test_real_memory_efficiency(self, small_real_data, medium_real_data):
513513
medium_result.peak_memory_mb / small_result.peak_memory_mb
514514
)
515515

516-
print(
516+
logging.info(
517517
f"Memory scaling: {memory_ratio:.2f}x memory for {data_ratio:.2f}x data"
518518
)
519519

@@ -557,7 +557,7 @@ def test_platform_specific_optimal_config():
557557
client = Client(cluster)
558558
configurations.append(("distributed_threaded", client, "threaded"))
559559
except Exception as e:
560-
print(f"Could not create threaded client: {e}")
560+
logging.info(f"Could not create threaded client: {e}")
561561

562562
# Configuration 4: Distributed processes (skip on Windows)
563563
if platform.system() != "Windows":
@@ -573,7 +573,7 @@ def test_platform_specific_optimal_config():
573573
("distributed_processes", client, "processes")
574574
)
575575
except Exception as e:
576-
print(f"Could not create process client: {e}")
576+
logging.info(f"Could not create process client: {e}")
577577

578578
results = []
579579

@@ -659,11 +659,11 @@ def test_platform_specific_optimal_config():
659659
save_benchmark_result(benchmark_result)
660660

661661
if success:
662-
print(
662+
logging.info(
663663
f"{config_name}: {compute_time:.3f}s, {mem_tracker.peak_memory:.1f}MB"
664664
)
665665
else:
666-
print(f"{config_name}: FAILED - {error_message}")
666+
logging.info(f"{config_name}: FAILED - {error_message}")
667667

668668
finally:
669669
# Clean up any clients
@@ -680,10 +680,10 @@ def test_platform_specific_optimal_config():
680680
successful_results = [r for r in results if r.success]
681681
if successful_results:
682682
optimal = min(successful_results, key=lambda x: x.compute_time)
683-
print(
683+
logging.info(
684684
f"\nOptimal configuration for {platform.system()}: {optimal.scheduler}"
685685
)
686-
print(
686+
logging.info(
687687
f"Time: {optimal.compute_time:.3f}s, Memory: {optimal.peak_memory_mb:.1f}MB"
688688
)
689689

@@ -708,6 +708,6 @@ def test_platform_specific_optimal_config():
708708
with open(rec_file, "w") as f:
709709
json.dump(recommendation, f, indent=2)
710710

711-
print(f"Saved platform recommendation to {rec_file}")
711+
logging.info(f"Saved platform recommendation to {rec_file}")
712712

713713
assert len(successful_results) > 0, "No benchmark configurations succeeded"

0 commit comments

Comments
 (0)