Merge pull request #317 from codeflash-ai/early-exit-slow-optimizations
Save some time in finding optimized candidates if a generated candida…
This commit is contained in:
commit
0e33f211a0
3 changed files with 17 additions and 2 deletions
|
|
@ -301,6 +301,7 @@ class Optimizer:
|
|||
overall_original_test_results=overall_original_test_results,
|
||||
original_gen_results=original_gen_results,
|
||||
generated_tests_path=generated_tests_path,
|
||||
best_runtime_until_now=best_runtime,
|
||||
)
|
||||
|
||||
if success:
|
||||
|
|
@ -621,6 +622,7 @@ class Optimizer:
|
|||
overall_original_test_results: TestResults,
|
||||
original_gen_results: TestResults,
|
||||
generated_tests_path: str,
|
||||
best_runtime_until_now: int,
|
||||
):
|
||||
success = True
|
||||
best_test_runtime = None
|
||||
|
|
@ -723,6 +725,11 @@ class Optimizer:
|
|||
times_run += 1
|
||||
if first_run:
|
||||
first_run = False
|
||||
if best_test_runtime is not None and (best_test_runtime > 3 * best_runtime_until_now):
|
||||
# If after 5 runs, the optimized candidate is taking 3 times longer than the best code until now,
|
||||
# then it is not a good optimization. Early exit to save time.
|
||||
success = True
|
||||
do_break = True
|
||||
if do_break:
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ def comparator(orig: Any, new: Any) -> bool:
|
|||
return False
|
||||
return True
|
||||
|
||||
if isinstance(orig, (str, int, bool, complex, type(None), decimal.Decimal)):
|
||||
if isinstance(orig, (str, int, bool, complex, type(None), decimal.Decimal, set)):
|
||||
return orig == new
|
||||
if isinstance(orig, float):
|
||||
if math.isnan(orig) and math.isnan(new):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import datetime
|
||||
import pytest
|
||||
import decimal
|
||||
import pytest
|
||||
|
||||
from codeflash.verification.comparator import comparator
|
||||
from codeflash.verification.equivalence import compare_results
|
||||
|
|
@ -62,6 +62,14 @@ def test_basic_python_objects():
|
|||
assert not comparator(a, c)
|
||||
assert not comparator(a, d)
|
||||
|
||||
a = {1, 2, 3}
|
||||
b = {2, 3, 1}
|
||||
c = {1, 2, 4}
|
||||
d = {1, 2, 3, 4}
|
||||
assert comparator(a, b)
|
||||
assert not comparator(a, c)
|
||||
assert not comparator(a, d)
|
||||
|
||||
|
||||
def test_standard_python_library_objects():
|
||||
a = datetime.datetime(2020, 2, 2, 2, 2, 2)
|
||||
|
|
|
|||
Loading…
Reference in a new issue