LLM Code Capabilities Tested: Refactoring, Source Understanding, and Model Selection

    Public benchmark scores rarely predict how a model performs on real engineering work. This article presents a reusable evaluation framework built from four real scenarios: source-level understanding, feature implementation, large-file refactoring, and architecture analysis. It also covers practical tactics for keeping long-context output stable, a formula for measuring cost per successful task rather than price per token, and a tiered routing strategy that sends simple tasks to cheaper models and complex refactoring to models with stronger long-context consistency. The takeaway: turn evaluation into a pipeline with fixed task sets, pass rates, average turns, latency, and historical trends so selection decisions are driven by data.

    1. Why Benchmark Scores Are Not Productivity

    When choosing a model, many teams start with public leaderboards. But leaderboard tasks are usually closed-ended, single-turn, and short in context, while real development work is multi-turn, noisy, and spans multiple files. A model that leads by a few points on a leaderboard can feel completely different in an actual project. Four things really determine efficiency: whether the model can read the existing design intent, whether it stays globally consistent across a long context, whether it can split a large file into sensible module boundaries, and the overall cost per task.

    A more reliable approach is to build a set of representative tasks from your own codebase, fix the prompts and acceptance criteria, and compare models side by side. The framework below is reusable and organized by dimension.

    2. Comparison Results Across Four Real Scenarios

    2.1 Source-Level Understanding: From “Reading” to “Understanding Why”

    Give the model a complex, open-source-style codebase and ask it to explain module responsibilities and key design trade-offs. In practice, weaker models can restate what the code does. Stronger models can explain why the code is layered that way, where the performance bottlenecks are, and which parts are redundant code kept for backward compatibility. The gap is not at the syntax level; it is in recovering intent and identifying trade-offs.

    A practical acceptance method is not to judge whether the answer “sounds right,” but to require verifiable assertions, for example:

    1. Please output:
    2. 1) A module dependency graph (in text form)
    3. 2) The core invariant of each module
    4. 3) Three places you think are most likely to break as traffic grows, with reasoning
    5. 4) A list of files that must change if one storage layer is replaced

    Only a model that reliably delivers items 2 and 4 qualifies to enter a refactoring workflow.

    2.2 Feature Implementation: Runnable and Tested Is the Only Delivery

    Ask the model to add several feature modules that follow the existing code style. Focus on three things: whether it follows the project’s conventions, whether it ships tests, and whether the change is minimal. In experience, mainstream models handle basic coding well, and naming and structure are generally sound. The real dividing line is exception and boundary handling: empty input, timeouts, retries, idempotency, and concurrent write conflicts. Make the constraints explicit in the prompt:

    1. Constraints:
    2. - Reuse existing utility functions in the repository; do not add third-party dependencies
    3. - Every new function must have a corresponding unit test covering at least one exception branch
    4. - Do not modify files unrelated to this requirement
    5. - Output the list of changed files and the command to run the tests

    2.3 Large-File Refactoring: Split Granularity and Global Control

    Splitting a giant file of more than a thousand lines is a touchstone for long-context stability. Two typical differences appear: one type of model splits more finely, produces more modules, and takes slightly longer per run; the other produces fewer files, runs faster, and holds the global structure more steadily. When the time cost is similar, finer splitting is not necessarily better. What matters is whether dependencies are clear afterward, whether circular references appear, and whether shared types are pushed down to a reasonable level.

    The idea behind a verification script:

    1. # Automated checks after the split
    2. check_imports # Detect circular dependencies
    3. run_tests # Confirm behavior is unchanged
    4. diff_public_api # Detect unintended changes to the public interface

    Refactoring succeeds only when all three pass. Otherwise, “more files” just moves complexity around.

    2.4 Architecture Analysis: Breadth vs. Actionability

    One type of model tends to score multiple dimensions in a table first, producing broad coverage. The other tends to walk the directory structure first, then give an optimization roadmap by priority and point to concrete improvements, such as a platform-native capability that is not being used. The former suits reporting and aligning understanding; the latter suits direct entry into iteration planning. Teams can split by purpose: use the former for review material and the latter for execution plans.

    3. Context Stability and Cost Control

    Long-context drift is common: as turns accumulate, a model may forget earlier constraints, repeat changes already made, or invent interfaces that do not exist. The mitigations are engineering practices, not model-switching guesswork:

    • Restate the key constraints as a checklist every turn to form a stable system prompt;
    • Break large tasks into small steps with acceptance points, avoiding too many files in a single pass;
    • Maintain a “done/pending” state file and have the model read it before acting each turn;
    • Run static checks and tests on generated output so automation acts as a safety net.

    On cost, billing and plan structures vary widely across models, so unit price alone is misleading. A more practical metric is cost per successful task:

    1. Cost per successful task = (input tokens + output tokens) x unit price / first-pass rate

    Some models consume fewer tokens and can save twenty to thirty percent on the same task, but need more turns to converge. Others have a higher first-pass rate and fewer total turns. Putting first-pass rate in the denominator often produces conclusions that run counter to intuition.

    4. A Practical Selection Strategy

    Overall, a sound tiered strategy is:

    1. Assign simple and medium tasks (scripts, single-file changes, test completion) to the more cost-effective option and optimize for throughput;
    2. Assign complex refactoring, source-level understanding, and cross-module design to the option with steadier long context and optimize for getting it right the first time;
    3. When the budget is tight, run both tracks in parallel and route tasks with rules;
    4. Whichever you choose, automated tests and static checks must act as quality gates.

    The routing logic can be minimal:

    1. def route(task):
    2. if task.files_touched <= 1 and task.complexity == "low":
    3. return "fast_model"
    4. if task.need_arch_reasoning or task.context_tokens > 200_000:
    5. return "stable_model"
    6. return "fast_model"

    5. Turn Evaluation into a Pipeline

    A one-off comparison only describes a moment in time, and models iterate quickly, so conclusions expire. Make evaluation a pipeline: prepare desensitized, representative repository samples, fix the task set and verification scripts, and run them automatically whenever a model version updates. Produce four metrics: pass rate, average turns, average latency, and cost per successful task, and keep the historical trend. This turns selection from a “feeling” into data.

    If you run this kind of evaluation on Baidu AI Cloud, you can place task samples in object storage, write execution results to a logging service, and track pass-rate fluctuations with monitoring and alerts, while using a container platform for isolated execution. The whole flow can then run unattended and continuously.

    6. Conclusion

    Leaderboard scores are only the starting point; engineering results are the finish line. Mainstream models today show no clear gap in basic coding. The differences concentrate in three areas: depth of understanding of design intent, completeness of exception and boundary handling, and global consistency in long contexts. Write these three into your acceptance criteria, back them with automated gates and continuous evaluation, and combine them with tiered routing to control cost. That is a sustainable way to do AI-assisted development.