Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fspin/rate_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ratecontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down