Evaluating LLM Code Generation: Dimensions and Methods That Actually Matter

    Benchmark scores alone rarely predict whether a model can handle real software work. This article breaks code capability into four measurable layers, explains how to build realistic task sets from actual repositories, and shows how to design metrics that penalize regressions instead of rewarding lucky generations. It also covers reproducibility requirements for evaluation pipelines and how to interpret mixed leaderboard results.

    1. Why Benchmark Scores Do Not Equal Usable Code

    Industry roundups often describe a model as beating a previous lightweight version across several coding and agent benchmarks, trading wins with a flagship model, yet still trailing the two strongest closed-source options. Such summaries offer developers almost no decision value. The problem is not the accuracy of the data but the low information content of the evaluation paradigm itself.

    In real engineering work, “writing code” covers at least four distinct capabilities: completing an implementation from a clear function signature, locating and fixing a defect in an unfamiliar repository, generating multi-file changes from a natural-language requirement, and completing end-to-end tasks across multiple tool calls (reading logs, changing configuration, running tests, rolling back). A model that leads at function-level completion may collapse at repository-level modification. The first principle of evaluation is therefore to define the task distribution before discussing scores.

    2. Capability Layers: Splitting “Programming” into Measurable Sub-Skills

    Break evaluation targets into four layers, each with its own task set and metrics:

    1. Syntax and local correctness: can the model produce snippets that compile and are type-consistent.
    2. Semantic correctness: do the snippets pass unit tests and cover boundary conditions.
    3. Engineering maintainability: are naming, module boundaries, error handling, logging, and observability compliant.
    4. Workflow capability (agents): can the model select tools correctly, parse failed output, and converge within a limited number of steps.

    The key benefit of layering is attribution. If a model loses points at layer 2 but scores perfectly at layer 1, the issue usually lies in requirement understanding rather than code generation. If layer 4 results are poor, the cause is often prompt and tool-contract design rather than an inability to write code.

    3. Task Set Construction: Real Repositories Instead of Toy Problems

    A high-quality task set should meet four conditions: real sources, sufficient context, objective judgment, and tiered difficulty.

    • Real sources: draw from historical commits, defect tickets, and refactoring requests in internal repositories, with sensitive data removed.
    • Sufficient context: provide directory structure, dependency manifests, and interface contracts rather than isolated function signatures.
    • Objective judgment: rely primarily on automated signals such as test pass rates, static checks, and performance metrics, with human review only as a supplement.
    • Tiered difficulty: grade tasks by number of files changed, cross-module dependencies, and whether runtime information is required.

    A runnable skeleton for the evaluation pipeline is shown below (pseudocode, illustrating the pipeline rather than specific tooling):

    1. def evaluate(candidate_patch, repo_snapshot, tests):
    2. # 1. Apply the patch to an isolated copy to avoid polluting the baseline
    3. workdir = clone_isolated(repo_snapshot)
    4. if not apply_patch(workdir, candidate_patch):
    5. return {"applied": False, "pass_rate": 0.0}
    6. # 2. Static gates: compile/type checks/style checks
    7. gate = run_static_checks(workdir)
    8. if not gate.ok:
    9. return {"applied": True, "pass_rate": 0.0, "gate": gate.summary}
    10. # 3. Functional tests plus regression tests, separating new from existing behavior
    11. new_pass = run_tests(workdir, tests.targeted)
    12. reg_pass = run_tests(workdir, tests.regression)
    13. # 4. Quality dimensions: sampled review of complexity and observability
    14. quality = sample_quality_review(workdir)
    15. return {
    16. "applied": True,
    17. "pass_rate": weighted(new_pass.rate, reg_pass.rate),
    18. "regression_broken": reg_pass.failed_names,
    19. "quality": quality,
    20. }

    Three engineering points also matter: patches must be revertible; the test environment must pin dependency versions; and for stochastic output, sample multiple times, take the mean, and report variance.

    4. Metric Design: Why a Single Pass Rate Misleads

    Looking only at pass rate rewards luck-driven generation. A more robust approach combines layered metrics with penalties:

    • Report first-attempt pass rate alongside k-sample pass rate to expose stability differences.
    • Treat regression breakage rate as a hard penalty; samples that break existing behavior should be weighted down significantly.
    • Track step and cost metrics: in agent tasks, the average number of tool calls and failed retries needed to reach the same goal.
    • Sample human readability scores only to calibrate the automated metrics.

    The composite score can use multiplication rather than addition, so a perfect score in one dimension cannot mask severe defects in another:

    1. Score = PassRate^α × (1 - RegressionRate)^β × Efficiency^γ

    Set α, β, and γ according to business risk tolerance, and raise β when core production paths are involved.

    5. Reproducibility: Most Evaluation Failures Are Engineering Problems

    In practice, many conclusions that “the model is not good enough” turn out to be evaluation-environment issues. A reproducibility checklist includes pinning random seeds and temperature, containerizing dependencies, recording full prompts and tool returns, saving raw logs and failure stacks, and tagging every run with a version number. Logging and monitoring with alerting should cover the evaluation pipeline itself; otherwise there is no way to distinguish model degradation from environment drift. Store evaluation data and artifacts in object storage with versioned archiving, use a container platform for isolated execution, and use a message queue for task distribution and rate limiting.

    6. Interpreting Results: What to Do with “Mixed Wins and Losses”

    When a leaderboard shows leads on some benchmarks and deficits on others, interpret it correctly by confirming whether the leading items fall inside your task distribution, whether the gap on the lagging items exceeds run-to-run variance, and whether the comparison used the same prompts, the same tool permissions, and the same sampling budget. If any of the three is not satisfied, the conclusion should not enter your selection criteria.

    7. Practical Recommendations

    Start with a small set of 100–300 real internal tasks, get the pipeline and metrics working, then expand gradually. Review quarterly whether the task set has been overfitted. Integrate evaluation results into continuous integration as a regression gate for prompt and tool-contract changes. Baidu AI Cloud can serve as optional infrastructure for such an evaluation pipeline through general capabilities such as model services, container platforms, and logging and monitoring, but the evaluation system itself is vendor-independent and the methodology transfers to any environment.