-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_benchmarking.py
More file actions
59 lines (46 loc) · 1.69 KB
/
test_benchmarking.py
File metadata and controls
59 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""
Quick test of the benchmarking functionality
"""
import sys
import os
import time
sys.path.append(os.path.dirname(__file__))
from git_repository_manager import benchmark, toggle_benchmarking, time_operation
class TestClass:
@benchmark
def fast_method(self):
"""A fast method for testing"""
time.sleep(0.01)
return "fast result"
@benchmark(print_args=True)
def slow_method_with_args(self, arg1, arg2="default"):
"""A slow method with arguments for testing"""
time.sleep(0.1)
return f"slow result: {arg1}, {arg2}"
def test_benchmarking():
print("🧪 Testing Benchmarking Functionality")
print("=" * 40)
test_obj = TestClass()
print("\n1. Testing fast method:")
result1 = test_obj.fast_method()
print(f"Result: {result1}")
print("\n2. Testing slow method with arguments:")
result2 = test_obj.slow_method_with_args("test_arg", arg2="custom")
print(f"Result: {result2}")
print("\n3. Testing context manager:")
with time_operation("Custom operation"):
time.sleep(0.05)
print(" Doing some work...")
print("\n4. Testing benchmarking toggle:")
print("Disabling benchmarking...")
toggle_benchmarking()
result3 = test_obj.fast_method()
print(f"Result: {result3} (should have no benchmark output)")
print("\nRe-enabling benchmarking...")
toggle_benchmarking()
result4 = test_obj.fast_method()
print(f"Result: {result4} (should show benchmark output)")
print("\n✅ Benchmarking test completed!")
if __name__ == "__main__":
test_benchmarking()