| |
| """ |
| Speed testing script for NFL play detection system. |
| Tests both individual clip processing and batch processing performance. |
| """ |
| import time |
| import os |
| import glob |
| from inference import predict_clip, transcribe_clip, analyze_play_state |
| from config import DEFAULT_DATA_DIR |
|
|
| def test_single_clip_speed(clip_path: str, num_runs: int = 5): |
| """Test speed of processing a single clip multiple times""" |
| print(f"\n=== Single Clip Speed Test ===") |
| print(f"Testing: {os.path.basename(clip_path)}") |
| print(f"Runs: {num_runs}") |
| |
| video_times = [] |
| audio_times = [] |
| |
| for i in range(num_runs): |
| print(f"Run {i+1}/{num_runs}...") |
| |
| |
| start_time = time.time() |
| video_results = predict_clip(clip_path) |
| video_time = time.time() - start_time |
| video_times.append(video_time) |
| |
| |
| start_time = time.time() |
| audio_result = transcribe_clip(clip_path) |
| audio_time = time.time() - start_time |
| audio_times.append(audio_time) |
| |
| |
| start_time = time.time() |
| play_state, confidence = analyze_play_state(video_results) |
| analysis_time = time.time() - start_time |
| |
| total_time = video_time + audio_time + analysis_time |
| print(f" Video: {video_time:.2f}s | Audio: {audio_time:.2f}s | Analysis: {analysis_time:.3f}s | Total: {total_time:.2f}s") |
| |
| |
| avg_video = sum(video_times) / len(video_times) |
| avg_audio = sum(audio_times) / len(audio_times) |
| avg_total = avg_video + avg_audio |
| |
| print(f"\n=== Average Times ===") |
| print(f"Video Classification: {avg_video:.2f}s") |
| print(f"Audio Transcription: {avg_audio:.2f}s") |
| print(f"Total per clip: {avg_total:.2f}s") |
| print(f"Estimated clips/minute: {60/avg_total:.1f}") |
| |
| return avg_video, avg_audio, avg_total |
|
|
| def test_batch_speed(input_dir: str = DEFAULT_DATA_DIR, max_clips: int = 10): |
| """Test speed of batch processing""" |
| print(f"\n=== Batch Processing Speed Test ===") |
| |
| |
| patterns = ["*.mov", "*.mp4"] |
| clips = [] |
| for pat in patterns: |
| clips.extend(glob.glob(os.path.join(input_dir, pat))) |
| clips = sorted(clips)[:max_clips] |
| |
| if not clips: |
| print(f"No clips found in '{input_dir}'") |
| return |
| |
| print(f"Processing {len(clips)} clips...") |
| |
| total_start = time.time() |
| clip_times = [] |
| |
| for i, clip in enumerate(clips): |
| clip_name = os.path.basename(clip) |
| print(f"[{i+1}/{len(clips)}] {clip_name}") |
| |
| clip_start = time.time() |
| |
| |
| video_results = predict_clip(clip) |
| play_state, confidence = analyze_play_state(video_results) |
| transcript = transcribe_clip(clip) |
| |
| clip_time = time.time() - clip_start |
| clip_times.append(clip_time) |
| |
| print(f" Time: {clip_time:.2f}s | Play State: {play_state} ({confidence:.3f})") |
| |
| total_time = time.time() - total_start |
| avg_clip_time = sum(clip_times) / len(clip_times) if clip_times else 0 |
| |
| print(f"\n=== Batch Results ===") |
| print(f"Total clips: {len(clips)}") |
| print(f"Total time: {total_time:.2f}s") |
| print(f"Average per clip: {avg_clip_time:.2f}s") |
| print(f"Clips per minute: {60/avg_clip_time:.1f}") |
| print(f"Time for 100 clips: ~{(avg_clip_time * 100)/60:.1f} minutes") |
| |
| return total_time, avg_clip_time |
|
|
| def test_pipeline_modes(input_dir: str = DEFAULT_DATA_DIR, max_clips: int = 5): |
| """Compare different pipeline processing modes""" |
| print(f"\n=== Pipeline Mode Comparison ===") |
| |
| |
| patterns = ["*.mov", "*.mp4"] |
| clips = [] |
| for pat in patterns: |
| clips.extend(glob.glob(os.path.join(input_dir, pat))) |
| clips = sorted(clips)[:max_clips] |
| |
| if not clips: |
| print(f"No clips found in '{input_dir}'") |
| return |
| |
| |
| print(f"\n🚀 Video-Only Processing ({len(clips)} clips)") |
| print("-" * 50) |
| video_start = time.time() |
| video_times = [] |
| |
| for i, clip in enumerate(clips, 1): |
| clip_name = os.path.basename(clip) |
| clip_start = time.time() |
| |
| scores = predict_clip(clip) |
| play_state, confidence = analyze_play_state(scores) |
| |
| clip_time = time.time() - clip_start |
| video_times.append(clip_time) |
| print(f"[{i}/{len(clips)}] {clip_name}: {clip_time:.2f}s | {play_state}") |
| |
| video_total = time.time() - video_start |
| video_avg = video_total / len(clips) |
| |
| |
| print(f"\n🎙️ Audio-Only Processing ({len(clips)} clips)") |
| print("-" * 50) |
| audio_start = time.time() |
| audio_times = [] |
| |
| for i, clip in enumerate(clips, 1): |
| clip_name = os.path.basename(clip) |
| clip_start = time.time() |
| |
| transcript = transcribe_clip(clip) |
| |
| clip_time = time.time() - clip_start |
| audio_times.append(clip_time) |
| print(f"[{i}/{len(clips)}] {clip_name}: {clip_time:.2f}s") |
| |
| audio_total = time.time() - audio_start |
| audio_avg = audio_total / len(clips) |
| |
| |
| combined_avg = video_avg + audio_avg |
| |
| print(f"\n📊 Pipeline Comparison Results") |
| print("=" * 50) |
| print(f"Video-only processing:") |
| print(f" Average per clip: {video_avg:.2f}s") |
| print(f" Throughput: {60/video_avg:.1f} clips/minute") |
| print(f" 100 clips: ~{video_avg*100/60:.1f} minutes") |
| |
| print(f"\nAudio-only processing:") |
| print(f" Average per clip: {audio_avg:.2f}s") |
| print(f" Throughput: {60/audio_avg:.1f} clips/minute") |
| print(f" 100 clips: ~{audio_avg*100/60:.1f} minutes") |
| |
| print(f"\nCombined (sequential phases):") |
| print(f" Total per clip: {combined_avg:.2f}s") |
| print(f" Throughput: {60/combined_avg:.1f} clips/minute") |
| print(f" 100 clips: ~{combined_avg*100/60:.1f} minutes") |
| |
| print(f"\nSpeed advantage of video-only: {audio_avg/video_avg:.1f}x faster") |
| |
| return { |
| "video_avg": video_avg, |
| "audio_avg": audio_avg, |
| "combined_avg": combined_avg, |
| "speedup": audio_avg/video_avg |
| } |
|
|
| def main(): |
| print("🏈 NFL Play Detection Speed Test") |
| print("=" * 50) |
| |
| |
| test_clips = glob.glob("data/*.mov") + glob.glob("data/*.mp4") |
| if not test_clips: |
| print("❌ No clips found in data/ directory") |
| return |
| |
| test_clip = test_clips[0] |
| |
| |
| avg_video, avg_audio, avg_total = test_single_clip_speed(test_clip, num_runs=3) |
| |
| |
| total_time, avg_clip_time = test_batch_speed(max_clips=5) |
| |
| |
| pipeline_results = test_pipeline_modes(max_clips=5) |
| |
| print(f"\n🎯 Performance Summary") |
| print(f"=" * 30) |
| print(f"Single clip average: {avg_total:.2f}s") |
| print(f"Batch average: {avg_clip_time:.2f}s") |
| print(f"Estimated throughput: {60/avg_clip_time:.1f} clips/minute") |
| |
| |
| print(f"\n📊 Processing Time Estimates:") |
| print(f" 10 clips: ~{(avg_clip_time * 10)/60:.1f} minutes") |
| print(f" 50 clips: ~{(avg_clip_time * 50)/60:.1f} minutes") |
| print(f" 100 clips: ~{(avg_clip_time * 100)/60:.1f} minutes") |
| print(f" 1 hour of 2s clips (1800): ~{(avg_clip_time * 1800)/60:.0f} minutes") |
| |
| print(f"\n🚀 Optimization Recommendations:") |
| print("=" * 40) |
| print(f"For continuous pipelines:") |
| print(f" • Use --video-only for {pipeline_results['speedup']:.1f}x faster processing") |
| print(f" • Process video in real-time, audio in batch later") |
| print(f" • Video-only: {60/pipeline_results['video_avg']:.1f} clips/min vs {60/pipeline_results['combined_avg']:.1f} clips/min full pipeline") |
|
|
| if __name__ == "__main__": |
| main() |