From abbd4067ae70475dd61013318648e7a56af2f4f9 Mon Sep 17 00:00:00 2001 From: Suke0811 <49264928+Suke0811@users.noreply.github.com> Date: Mon, 24 Nov 2025 13:50:36 -0800 Subject: [PATCH] Fix total iteration reporting to include warmup --- fspin/rate_control.py | 4 +++- tests/test_ratecontrol.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fspin/rate_control.py b/fspin/rate_control.py index fa7dfc1..bb81630 100644 --- a/fspin/rate_control.py +++ b/fspin/rate_control.py @@ -484,13 +484,15 @@ def get_report(self, output=True): Returns: dict: Performance statistics as a dictionary. """ - if not self.report or not self.iteration_times: + if not self.report or (not self.iteration_times and self.initial_duration is None): self.logger.output("No iterations were recorded.") return {} end_time = self.end_time or time.perf_counter() total_duration = end_time - self.start_time total_iterations = len(self.iteration_times) + if self.initial_duration is not None: + total_iterations += 1 avg_function_duration = mean(self.iteration_times) if self.iteration_times else 0 avg_deviation = mean(self.deviations) if self.deviations else 0 max_deviation = max(self.deviations) if self.deviations else 0 diff --git a/tests/test_ratecontrol.py b/tests/test_ratecontrol.py index b6e6698..83bae3e 100644 --- a/tests/test_ratecontrol.py +++ b/tests/test_ratecontrol.py @@ -76,6 +76,22 @@ def work(): assert len(rc.iteration_times) == 1 +def test_spin_sync_report_counts_warmup_iteration(): + calls = [] + + def condition(): + return len(calls) < 2 + + @spin(freq=1000, condition_fn=condition, report=True, thread=False) + def work(): + calls.append(time.perf_counter()) + + rc = work() + report = rc.get_report(output=False) + + assert report.get("total_iterations") == len(calls) + + def test_spin_sync_default_condition(): calls = []