Skip to content

Commit f8255fb

Browse files
fix: unit tests
1 parent 733de24 commit f8255fb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

codeflash/result/critic.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def performance_gain(*, original_runtime_ns: int, optimized_runtime_ns: int) ->
2626

2727

2828
def speedup_critic(
29-
candidate_result: OptimizedCandidateResult, original_code_runtime: int, best_runtime_until_now: int
29+
candidate_result: OptimizedCandidateResult,
30+
original_code_runtime: int,
31+
best_runtime_until_now: int,
32+
disable_gh_action_noise: bool | None = None,
3033
) -> bool:
3134
"""Take in a correct optimized Test Result and decide if the optimization should actually be surfaced to the user.
3235
@@ -35,10 +38,11 @@ def speedup_critic(
3538
when the original runtime is less than 10 microseconds, and becomes MIN_IMPROVEMENT_THRESHOLD for any higher runtime.
3639
The noise floor is doubled when benchmarking on a (noisy) GitHub Action virtual instance, also we want to be more confident there.
3740
"""
38-
in_github_actions_mode = bool(env_utils.get_pr_number())
3941
noise_floor = 3 * MIN_IMPROVEMENT_THRESHOLD if original_code_runtime < 10000 else MIN_IMPROVEMENT_THRESHOLD
40-
if in_github_actions_mode:
41-
noise_floor = noise_floor * 2 # Increase the noise floor in GitHub Actions mode
42+
if not disable_gh_action_noise:
43+
in_github_actions_mode = bool(env_utils.get_pr_number())
44+
if in_github_actions_mode:
45+
noise_floor = noise_floor * 2 # Increase the noise floor in GitHub Actions mode
4246

4347
perf_gain = performance_gain(
4448
original_runtime_ns=original_code_runtime, optimized_runtime_ns=candidate_result.best_test_runtime

tests/test_critic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_speedup_critic() -> None:
4141
total_candidate_timing=12,
4242
)
4343

44-
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now) # 20% improvement
44+
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 20% improvement
4545

4646
candidate_result = OptimizedCandidateResult(
4747
max_loop_count=5,
@@ -52,7 +52,7 @@ def test_speedup_critic() -> None:
5252
optimization_candidate_index=0,
5353
)
5454

55-
assert not speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now) # 6% improvement
55+
assert not speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 6% improvement
5656

5757
original_code_runtime = 100000
5858
best_runtime_until_now = 100000
@@ -66,7 +66,7 @@ def test_speedup_critic() -> None:
6666
optimization_candidate_index=0,
6767
)
6868

69-
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now) # 6% improvement
69+
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 6% improvement
7070

7171

7272
def test_generated_test_critic() -> None:

0 commit comments

Comments
 (0)