Skip to content

Commit 70360c6

Browse files
committed
absolute value of percentage
1 parent 36b9c75 commit 70360c6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

codeflash/code_utils/edit_generated_tests.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,16 @@ def leave_SimpleStatementLine(
133133
optimized_time = min(matching_optimized_times)
134134
if original_time != 0 and optimized_time != 0:
135135
perf_gain = format_perf(
136-
performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time)
137-
* 100
136+
abs(
137+
performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time)
138+
* 100
139+
)
138140
)
141+
status = "slower" if optimized_time > original_time else "faster"
139142
# Create the runtime comment
140-
comment_text = f"# {format_time(original_time)} -> {format_time(optimized_time)} ({perf_gain}%)"
143+
comment_text = (
144+
f"# {format_time(original_time)} -> {format_time(optimized_time)} ({perf_gain}% {status})"
145+
)
141146

142147
# Add comment to the trailing whitespace
143148
new_trailing_whitespace = cst.TrailingWhitespace(

tests/test_add_runtime_comments.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def test_add_runtime_comments_simple_function(self, test_config):
530530
)
531531

532532
expected_source = '''def test_function():
533-
codeflash_output = some_function() # 1.00s -> 500ms (100%)
533+
codeflash_output = some_function() # 1.00s -> 500ms (100% faster)
534534
assert codeflash_output == expected
535535
'''
536536

@@ -573,7 +573,7 @@ def test_function(self):
573573

574574
expected_source = '''class TestClass:
575575
def test_function(self):
576-
codeflash_output = some_function() # 2.00s -> 1.00s (100%)
576+
codeflash_output = some_function() # 2.00s -> 1.00s (100% faster)
577577
assert codeflash_output == expected
578578
'''
579579

@@ -617,9 +617,9 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
617617

618618
expected_source = '''def test_function():
619619
setup_data = prepare_test()
620-
codeflash_output = some_function() # 1.50s -> 750ms (100%)
620+
codeflash_output = some_function() # 1.50s -> 750ms (100% faster)
621621
assert codeflash_output == expected
622-
codeflash_output = another_function() # 1.50s -> 750ms (100%)
622+
codeflash_output = another_function() # 1.50s -> 750ms (100% faster)
623623
assert codeflash_output == expected2
624624
'''
625625

@@ -759,12 +759,12 @@ def test_add_runtime_comments_multiple_tests(self, test_config):
759759
)
760760

761761
expected_source1 = '''def test_function1():
762-
codeflash_output = some_function() # 1.00s -> 500ms (100%)
762+
codeflash_output = some_function() # 1.00s -> 500ms (100% faster)
763763
assert codeflash_output == expected
764764
'''
765765

766766
expected_source2 = '''def test_function2():
767-
codeflash_output = another_function() # 2.00s -> 800ms (150%)
767+
codeflash_output = another_function() # 2.00s -> 800ms (150% faster)
768768
assert codeflash_output == expected
769769
'''
770770

@@ -805,7 +805,7 @@ def test_add_runtime_comments_performance_regression(self, test_config):
805805
)
806806

807807
expected_source = '''def test_function():
808-
codeflash_output = some_function() # 1.00s -> 1.50s (-33.3%)
808+
codeflash_output = some_function() # 1.00s -> 1.50s (33.3% slower)
809809
assert codeflash_output == expected
810810
'''
811811

0 commit comments

Comments
 (0)