Skip to content

Commit 4d4cb5f

Browse files
authored
Merge pull request #2059 from codeflash-ai/refactor/benchmarks-to-dotcodeflash
Move benchmarks to .codeflash/benchmarks/
2 parents 819a56c + 8959ead commit 4d4cb5f

12 files changed

Lines changed: 24 additions & 11 deletions

tests/benchmarks/test_benchmark_code_extract_code_context.py renamed to .codeflash/benchmarks/test_benchmark_code_extract_code_context.py

File renamed without changes.
File renamed without changes.

tests/benchmarks/test_benchmark_discover_unit_tests.py renamed to .codeflash/benchmarks/test_benchmark_discover_unit_tests.py

File renamed without changes.

tests/benchmarks/test_benchmark_libcst_multi_file.py renamed to .codeflash/benchmarks/test_benchmark_libcst_multi_file.py

File renamed without changes.
File renamed without changes.

tests/benchmarks/test_benchmark_merge_test_results.py renamed to .codeflash/benchmarks/test_benchmark_merge_test_results.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from codeflash.verification.parse_test_output import merge_test_results
33

44

5-
def generate_test_invocations(count=100):
5+
def generate_test_invocations(count: int = 100) -> tuple[TestResults, TestResults]:
66
"""Generate a set number of test invocations for benchmarking."""
77
test_results_xml = TestResults()
88
test_results_bin = TestResults()
@@ -21,7 +21,7 @@ def generate_test_invocations(count=100):
2121
function_getting_tested="sorter",
2222
iteration_id=iteration_id,
2323
),
24-
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
24+
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py", # noqa: S108
2525
did_pass=True,
2626
runtime=None if i % 3 == 0 else i * 100, # Vary runtime values
2727
test_framework="unittest",
@@ -42,7 +42,7 @@ def generate_test_invocations(count=100):
4242
function_getting_tested="sorter",
4343
iteration_id=iteration_id,
4444
),
45-
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
45+
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py", # noqa: S108
4646
did_pass=True,
4747
runtime=500 + i * 20, # Generate varying runtime values
4848
test_framework="unittest",
@@ -56,12 +56,12 @@ def generate_test_invocations(count=100):
5656
return test_results_xml, test_results_bin
5757

5858

59-
def run_merge_benchmark(count=100):
59+
def run_merge_benchmark(count: int = 100) -> None:
6060
test_results_xml, test_results_bin = generate_test_invocations(count)
6161

6262
# Perform the merge operation that will be benchmarked
6363
merge_test_results(xml_test_results=test_results_xml, bin_test_results=test_results_bin, test_framework="unittest")
6464

6565

66-
def test_benchmark_merge_test_results(benchmark):
66+
def test_benchmark_merge_test_results(benchmark) -> None:
6767
benchmark(run_merge_benchmark, 1000) # Default to 100 test invocations

codeflash.code-workspace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"tests/",
1717
"-vv",
1818
"--ignore",
19-
"tests/benchmarks/"
19+
".codeflash/benchmarks/"
2020
],
2121
},
2222
"launch": {

codeflash/cli_cmds/cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ def process_pyproject_config(args: Namespace) -> Namespace:
156156
raise AssertionError("--tests-root must be specified")
157157
assert Path(args.tests_root).is_dir(), f"--tests-root {args.tests_root} must be a valid directory"
158158
if args.benchmark:
159-
assert args.benchmarks_root is not None, "--benchmarks-root must be specified when running with --benchmark"
159+
if args.benchmarks_root is None:
160+
# Auto-discover .codeflash/benchmarks/ convention
161+
candidate = Path.cwd() / ".codeflash" / "benchmarks"
162+
if candidate.is_dir():
163+
args.benchmarks_root = str(candidate)
164+
else:
165+
msg = "--benchmarks-root must be specified when running with --benchmark, or .codeflash/benchmarks/ must exist"
166+
raise AssertionError(msg)
160167
assert Path(args.benchmarks_root).is_dir(), (
161168
f"--benchmarks-root {args.benchmarks_root} must be a valid directory"
162169
)

codeflash/cli_cmds/cmd_compare.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ def run_compare(args: Namespace) -> None:
8787
benchmarks_root_str = pyproject_config.get("benchmarks_root")
8888

8989
if not benchmarks_root_str:
90-
logger.error("benchmarks-root must be configured in [tool.codeflash] to use compare")
91-
sys.exit(1)
90+
# Auto-discover .codeflash/benchmarks/ if it exists
91+
candidate = project_root / ".codeflash" / "benchmarks"
92+
if candidate.is_dir():
93+
benchmarks_root_str = str(candidate)
94+
logger.info(f"Auto-discovered benchmarks at {candidate}")
95+
else:
96+
logger.error("benchmarks-root must be configured in [tool.codeflash] or .codeflash/benchmarks/ must exist")
97+
sys.exit(1)
9298

9399
benchmarks_root = Path(benchmarks_root_str).resolve()
94100
if not benchmarks_root.is_dir():

0 commit comments

Comments
 (0)