-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_performance.py
More file actions
145 lines (109 loc) · 4.57 KB
/
test_performance.py
File metadata and controls
145 lines (109 loc) · 4.57 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
"""
Performance testing script for PoseDetector
Run this to test processing speed with different frame sizes
"""
import sys
import os
import time
import numpy as np
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from pose_detector import PoseDetector
def test_performance():
"""Test PoseDetector performance with different frame sizes"""
print("🚀 Performance Testing PoseDetector")
print("=" * 50)
# Test different frame sizes
frame_sizes = [
(480, 640, 3), # Standard definition
(720, 1280, 3), # HD
(1080, 1920, 3), # Full HD
(1440, 2560, 3), # 2K
]
detector = PoseDetector()
try:
for height, width, channels in frame_sizes:
print(f"\n📏 Testing frame size: {width}x{height}")
# Create test frame
frame = np.random.randint(0, 255, (height, width, channels), dtype=np.uint8)
# Warm up (first few frames are slower)
print(" Warming up...")
for _ in range(3):
detector.detect_pose(frame)
# Performance test
print(" Running performance test...")
start_time = time.time()
num_frames = 50
for _ in range(num_frames):
detector.detect_pose(frame)
end_time = time.time()
# Calculate metrics
total_time = end_time - start_time
fps = num_frames / total_time
avg_time_per_frame = total_time / num_frames * 1000 # in milliseconds
print(f" ✅ Processed {num_frames} frames in {total_time:.2f}s")
print(f" 📊 Performance: {fps:.1f} FPS")
print(f" ⏱️ Average time per frame: {avg_time_per_frame:.1f}ms")
# Memory usage info
frame_size_mb = (height * width * channels) / (1024 * 1024)
print(f" 💾 Frame size: {frame_size_mb:.1f} MB")
finally:
detector.release()
print("\n🧹 Cleanup completed")
def test_memory_usage():
"""Test memory usage with continuous processing"""
print("\n💾 Memory Usage Test")
print("=" * 30)
detector = PoseDetector()
try:
# Create a moderate-sized frame
frame = np.random.randint(0, 255, (720, 1280, 3), dtype=np.uint8)
print("Processing 100 frames to test memory stability...")
for i in range(100):
if i % 20 == 0:
print(f" Processed {i} frames...")
result = detector.detect_pose(frame)
# Simulate some processing delay
time.sleep(0.01)
print(" ✅ Memory test completed successfully")
finally:
detector.release()
def test_error_handling_performance():
"""Test performance when handling invalid inputs"""
print("\n⚠️ Error Handling Performance Test")
print("=" * 40)
detector = PoseDetector()
try:
# Test with various invalid inputs
invalid_inputs = [
None,
np.array([]),
np.random.randint(0, 255, (480, 640), dtype=np.uint8), # 2D
np.random.randint(0, 255, (480, 640, 4), dtype=np.uint8), # Wrong channels
]
start_time = time.time()
for i, invalid_input in enumerate(invalid_inputs):
result = detector.detect_pose(invalid_input)
assert result is None, f"Should handle invalid input {i} gracefully"
end_time = time.time()
print(f" ✅ Processed {len(invalid_inputs)} invalid inputs in {(end_time - start_time)*1000:.1f}ms")
print(f" 📊 Average time per invalid input: {(end_time - start_time)/len(invalid_inputs)*1000:.1f}ms")
finally:
detector.release()
if __name__ == "__main__":
try:
test_performance()
test_memory_usage()
test_error_handling_performance()
print("\n🎯 All performance tests completed successfully!")
print("\n📋 Performance Summary:")
print(" • Frame processing speed tested")
print(" • Memory usage stability verified")
print(" • Error handling performance measured")
print(" • Resource cleanup confirmed")
except Exception as e:
print(f"\n❌ Performance test failed: {e}")
import traceback
traceback.print_exc()
sys.exit(1)