Skip to content

Commit 4a68aa0

Browse files
committed
minor fixes
1 parent 30410ff commit 4a68aa0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

codeflash/code_utils/edit_generated_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from codeflash.cli_cmds.console import logger
88
from codeflash.code_utils.time_utils import format_time
99
from codeflash.models.models import GeneratedTests, GeneratedTestsList
10+
from codeflash.result.critic import performance_gain
1011
from codeflash.verification.verification_utils import TestConfig
1112

1213

@@ -127,9 +128,9 @@ def leave_SimpleStatementLine(
127128
if matching_original_times and matching_optimized_times:
128129
original_time = min(matching_original_times)
129130
optimized_time = min(matching_optimized_times)
130-
131+
perf_gain = performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time)
131132
# Create the runtime comment
132-
comment_text = f"# {format_time(original_time)} -> {format_time(optimized_time)}"
133+
comment_text = f"# {format_time(original_time)} -> {format_time(optimized_time)} ({perf_gain:.2f}%)"
133134

134135
# Add comment to the trailing whitespace
135136
new_trailing_whitespace = cst.TrailingWhitespace(

codeflash/result/create_pr.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from codeflash.code_utils.github_utils import github_pr_url
2020
from codeflash.code_utils.time_utils import format_time
2121
from codeflash.github.PrComment import FileDiffContent, PrComment
22+
from codeflash.result.critic import performance_gain
2223

2324
if TYPE_CHECKING:
2425
from codeflash.models.models import FunctionCalledInTest
@@ -89,7 +90,7 @@ def existing_tests_source_for(
8990
print_original_runtime = "NaN"
9091
else:
9192
print_original_runtime = format_time(original_tests_to_runtimes[filename][qualified_name])
92-
arrow = "\\rightarrow"
93+
arrow = "->"
9394
if (
9495
original_tests_to_runtimes[filename][qualified_name] != 0
9596
and optimized_tests_to_runtimes[filename][qualified_name] != 0
@@ -98,13 +99,17 @@ def existing_tests_source_for(
9899
optimized_tests_to_runtimes[filename][qualified_name]
99100
> original_tests_to_runtimes[filename][qualified_name]
100101
)
102+
perf_gain = performance_gain(
103+
original_runtime_ns=original_tests_to_runtimes[filename][qualified_name],
104+
optimized_runtime_ns=optimized_tests_to_runtimes[filename][qualified_name],
105+
)
101106
if greater:
102-
output += f" - $$\\color{{red}}{qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime}$$\n"
107+
output += f" - {qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime} $$\\color{{red}}({perf_gain:.2f}\\\\%)$$\n"
103108
else:
104-
output += f" - $$\\color{{green}}{qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime}$$\n"
109+
output += f" - {qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime} $$\\color{{green}}({perf_gain:.2f}\\\\%)$$\n"
105110
else:
106111
# one of them is NaN
107-
output += f" - $$\\color{{blue}}{qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime}$$\n"
112+
output += f" - {qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime}\n"
108113
# output += f"$$\\colorbox{{pink}}\{{ - {qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime}}}$$\n"
109114
output += "\n"
110115
return output

0 commit comments

Comments
 (0)