fix tests, correct perf calc

This commit is contained in:
aseembits93 2025-06-17 16:29:54 -07:00
parent e202289686
commit 7b4bdd053a
3 changed files with 22 additions and 4 deletions

View file

@ -131,7 +131,9 @@ def add_runtime_comments_to_generated_tests(
if matching_original_times and matching_optimized_times:
original_time = min(matching_original_times)
optimized_time = min(matching_optimized_times)
perf_gain = performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time)
perf_gain = (
performance_gain(original_runtime_ns=original_time, optimized_runtime_ns=optimized_time) * 100
)
# Create the runtime comment
comment_text = f"# {format_time(original_time)} -> {format_time(optimized_time)} ({perf_gain:.2f}%)"

View file

@ -99,9 +99,12 @@ def existing_tests_source_for(
optimized_tests_to_runtimes[filename][qualified_name]
> original_tests_to_runtimes[filename][qualified_name]
)
perf_gain = performance_gain(
original_runtime_ns=original_tests_to_runtimes[filename][qualified_name],
optimized_runtime_ns=optimized_tests_to_runtimes[filename][qualified_name],
perf_gain = (
performance_gain(
original_runtime_ns=original_tests_to_runtimes[filename][qualified_name],
optimized_runtime_ns=optimized_tests_to_runtimes[filename][qualified_name],
)
* 100
)
if greater:
output += f" - {qualified_name}: {print_original_runtime} {arrow} {print_optimized_runtime} $$\\color{{red}}({perf_gain:.2f}\\\\%)$$\n"

View file

@ -12,6 +12,7 @@ from codeflash.models.models import (
TestType,
VerificationType,
)
from codeflash.verification.verification_utils import TestConfig
class TestAddRuntimeComments:
@ -48,6 +49,18 @@ class TestAddRuntimeComments:
assert codeflash_output == [1, 2, 3]
"""
"""test_cfg: TestConfig,
generated_tests: GeneratedTestsList,
original_runtimes: dict[InvocationId, list[int]],
optimized_runtimes: dict[InvocationId, list[int]]"""
project_root_path = file_path.parent.resolve()
test_config = TestConfig(
tests_root="tests",
tests_project_rootdir=Path.cwd(),
project_root_path=project_root_path,
test_framework="pytest",
pytest_cmd="pytest",
)
generated_test = GeneratedTests(
generated_original_test_source=test_source,
instrumented_behavior_test_source="",