Skip to content

Commit

Permalink
refactor: replace hardcoded outlier factor for improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jan 28, 2025
1 parent 6e1d63e commit 4333c1f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pytest_codspeed/instruments/walltime.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
TIMER_RESOLUTION_NS = get_clock_info("perf_counter").resolution * 1e9
DEFAULT_MIN_ROUND_TIME_NS = TIMER_RESOLUTION_NS * 1_000_000

IQR_OUTLIER_FACTOR = 1.5
STDEV_OUTLIER_FACTOR = 3


@dataclass
class BenchmarkConfig:
Expand Down Expand Up @@ -89,12 +92,16 @@ def from_list(
)
iqr_ns = q3_ns - q1_ns
iqr_outlier_rounds = sum(
1 for t in times_ns if t < q1_ns - 1.5 * iqr_ns or t > q3_ns + 1.5 * iqr_ns
1
for t in times_ns
if t < q1_ns - IQR_OUTLIER_FACTOR * iqr_ns
or t > q3_ns + IQR_OUTLIER_FACTOR * iqr_ns
)
stdev_outlier_rounds = sum(
1
for t in times_ns
if t < mean_ns - 3 * stdev_ns or t > mean_ns + 3 * stdev_ns
if t < mean_ns - STDEV_OUTLIER_FACTOR * stdev_ns
or t > mean_ns + STDEV_OUTLIER_FACTOR * stdev_ns
)

return cls(
Expand Down

0 comments on commit 4333c1f

Please sign in to comment.