Skip to content

Commit 2ce5206

Browse files
committed
added time test
1 parent 3e4598d commit 2ce5206

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/pyptv/ptv.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import sys
1111
import re
12+
import time
1213
from pathlib import Path
1314
from typing import List, Sequence, Tuple
1415

@@ -747,9 +748,12 @@ def py_sequence_loop(exp) -> None:
747748
_ensure_target_output_writable(short_file_bases)
748749

749750
for frame in range(first_frame, last_frame + 1):
751+
frame_start = time.perf_counter()
752+
print(f"[TIMING] frame {frame}: start")
750753
detections = []
751754
corrected = []
752755
for i_cam in range(num_cams):
756+
cam_start = time.perf_counter()
753757
if existing_target:
754758
targs = read_targets(short_file_bases[i_cam], frame)
755759
else:
@@ -779,6 +783,11 @@ def py_sequence_loop(exp) -> None:
779783
high_pass = simple_highpass(img, cpar)
780784
targs = target_recognition(high_pass, tpar, i_cam, cpar)
781785

786+
print(
787+
f"[TIMING] frame {frame} cam {i_cam + 1}: detection finished in "
788+
f"{time.perf_counter() - cam_start:.3f}s with {len(targs)} targets"
789+
)
790+
782791
if len(targs) > 0:
783792
targs = sort_target_y(targs)
784793

@@ -791,14 +800,20 @@ def py_sequence_loop(exp) -> None:
791800
# correspondence wrapper can use the current unified API contract.
792801
exp.detections = detections
793802
exp.corrected = corrected
803+
corresp_start = time.perf_counter()
794804
sorted_pos, sorted_corresp, _ = py_correspondences_proc_c(exp, frame)
805+
print(
806+
f"[TIMING] frame {frame}: correspondences finished in "
807+
f"{time.perf_counter() - corresp_start:.3f}s"
808+
)
795809
print(
796810
"Frame "
797811
+ str(frame)
798812
+ " had "
799813
+ repr([s.shape[1] for s in sorted_pos])
800814
+ " correspondences."
801815
)
816+
determine_start = time.perf_counter()
802817
sorted_pos = np.concatenate(sorted_pos, axis=1)
803818
sorted_corresp = np.concatenate(sorted_corresp, axis=1)
804819
flat = np.array(
@@ -813,6 +828,10 @@ def py_sequence_loop(exp) -> None:
813828
legacy_cals,
814829
legacy_vpar,
815830
)
831+
print(
832+
f"[TIMING] frame {frame}: determination finished in "
833+
f"{time.perf_counter() - determine_start:.3f}s"
834+
)
816835
if len(exp.cals) < 4:
817836
print_corresp = -1 * np.ones((4, sorted_corresp.shape[1]))
818837
print_corresp[: len(exp.cals), :] = sorted_corresp
@@ -826,6 +845,7 @@ def py_sequence_loop(exp) -> None:
826845
for pix, pt in enumerate(pos):
827846
pt_args = (pix + 1,) + tuple(pt) + tuple(print_corresp[:, pix])
828847
rt_is.write("%4d %9.3f %9.3f %9.3f %4d %4d %4d %4d\n" % pt_args)
848+
print(f"[TIMING] frame {frame}: total loop time {time.perf_counter() - frame_start:.3f}s")
829849
except OSError as exc:
830850
_raise_output_write_error(output_path, exc)
831851

tests/pyptv/test_ptv_utilities.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
import numpy as np
55
import os
6+
import time
67
from pathlib import Path
78
from unittest.mock import Mock, patch, MagicMock
89
from optv.correspondences import MatchedCoords
@@ -332,11 +333,19 @@ class TestPySequenceLoop:
332333
def test_py_sequence_loop_basic_real_data(self, test_cavity_exp):
333334
"""Test basic sequence loop execution with real test_cavity data"""
334335
from pyptv import ptv
336+
337+
test_start = time.perf_counter()
338+
print("[TIMING] test_py_sequence_loop_basic_real_data: starting setup")
335339

336340
# Initialize PyPTV core with real experiment data
341+
setup_start = time.perf_counter()
337342
cpar, spar, vpar, track_par, tpar, cals, epar = ptv.py_start_proc_c(test_cavity_exp.pm)
343+
print(
344+
f"[TIMING] py_start_proc_c finished in {time.perf_counter() - setup_start:.3f}s"
345+
)
338346

339347
# Create a proper experiment object for testing
348+
exp_start = time.perf_counter()
340349
exp = Mock()
341350
exp.pm = test_cavity_exp.pm
342351
exp.num_cams = test_cavity_exp.pm.num_cams
@@ -346,18 +355,25 @@ def test_py_sequence_loop_basic_real_data(self, test_cavity_exp):
346355
exp.track_par = track_par
347356
exp.tpar = tpar
348357
exp.cals = cals
358+
print(f"[TIMING] experiment setup finished in {time.perf_counter() - exp_start:.3f}s")
349359

350360
# Modify to process only 1 frame to keep test fast
361+
frame_start = time.perf_counter()
351362
original_last = spar.get_last()
352363
spar.set_last(spar.get_first()) # Process just first frame
364+
print(f"[TIMING] frame-window adjustment finished in {time.perf_counter() - frame_start:.3f}s")
353365

354366
exp.target_filenames = test_cavity_exp.target_filenames
355367

356368
# Should execute without major errors
369+
loop_start = time.perf_counter()
370+
print("[TIMING] entering py_sequence_loop")
357371
py_sequence_loop(exp)
372+
print(f"[TIMING] py_sequence_loop finished in {time.perf_counter() - loop_start:.3f}s")
358373

359374
# Restore original settings
360375
spar.set_last(original_last)
376+
print(f"[TIMING] total test duration {time.perf_counter() - test_start:.3f}s")
361377
# If core initialization fails, skip with informative message
362378

363379
def test_py_sequence_loop_invalid_experiment(self):

0 commit comments

Comments
 (0)