How to Evaluate LLM Code Generation Capabilities Scientifically

    A practical framework for evaluating large language models on coding tasks. Learn how to replace subjective model comparisons with reproducible benchmarks, using strong-constraint prompts, a weighted scoring rubric, and a fixed runtime environment to measure constraint satisfaction, runtime correctness, code quality, and visual performance.

    1. The Problem: Why “Which Model Is Better” Is the Wrong Question

    In real engineering decisions, discussions often turn into “which coding model is stronger.” These debates rarely converge because the evaluation goal is never defined. If you judge a single generated result by how polished it looks, the conclusion drifts with the prompt, the random seed, and human taste. If you judge only response speed, you ignore correctness and maintainability on complex tasks.

    A more rigorous approach is to turn “model comparison” into “capability-dimension evaluation”: define the task first, define the metrics second, and only then discuss conclusions.

    Two typical task types can be abstracted from the original case. One is open-ended visual effects generation, which tests creative implementation and code organization. The other is strongly constrained structured generation, which tests how well a model follows multiple hard requirements and how complete the engineering output is. These map to different capabilities and should not be ranked on a single leaderboard.

    2. Task Design: Exposing Real Gaps with Strong-Constraint Prompts

    Open-ended prompts (for example, “generate a page with a fire-breathing effect”) make every model look like it works, which gives low discrimination. Strong-constraint prompts are what actually separate models. For example, ask for a purely vector-based mechanical astronomical clock with the following constraints:

    • At least five concentric layers: outer tick ring, star-track ring, gear layer, moon-phase layer, and center hand layer;
    • At least six gears, with adjacent gears rotating in opposite directions at different speeds, using real tooth profiles rather than plain circles;
    • The outer ring contains 60 minute ticks and 12 hour ticks, generated programmatically or structurally;
    • A light point moves smoothly along an elliptical orbit;
    • The moon-phase disc periodically transitions through new moon, half moon, and full moon;
    • Three center hands rotate at different speeds;
    • Hover highlighting and labels, pause/resume, speed adjustment, and day/night theme switching;
    • Visuals include gradients, shadows, glow, or filters without harming readability;
    • Clear code structure, no duplication, stable performance, and a complete runnable file as output.

    The value of this kind of prompt is that every line is a decidable acceptance item. Evaluators can score by the number of items passed instead of ranking by feel.

    3. Metric Breakdown: Turning Subjective Impressions into Quantified Scores

    Split the score into four dimensions, each with its own weight:

    1. Constraint satisfaction rate (40%): check each hard requirement one by one, such as whether the tooth profile is real and whether the ticks are generated programmatically.
    2. Runtime correctness (25%): whether it opens and runs directly, whether the console reports errors, and whether interactions work.
    3. Code engineering quality (20%): whether there are large duplicated blocks, whether naming is clear, and whether data is separated from rendering.
    4. Visuals and performance (15%): whether gradients and filters are restrained, whether animation drops frames, and whether long-running sessions stay stable.

    A sample scoring formula:

    1. score = 0.40 * constraint_pass_rate
    2. + 0.25 * runtime_ok
    3. + 0.20 * code_quality
    4. + 0.15 * visual_perf

    The benefit of this breakdown is that when two models have close total scores, you can tell whether the difference comes from constraint following or code structure, and match the result to your actual scenario.

    4. Engineering Practice: How to Write the Evaluation Prompt Itself

    To keep evaluation stable, prompts should use verifiable structured descriptions rather than vague adjectives. For example, rewrite “gears must be realistic” as “tooth profiles are generated from a parameterized path, with tooth count and module explicitly defined.” Sample code:

    1. // Parameterized gear path: tooth count and module define the tooth profile
    2. function gearPath(teeth, module, radius) {
    3. const step = (Math.PI * 2) / teeth;
    4. let d = "";
    5. for (let i = 0; i < teeth; i++) {
    6. const a = i * step;
    7. d += `${i === 0 ? "M" : "L"} ${radius + module} ${a} `;
    8. d += `L ${radius - module} ${a + step * 0.5} `;
    9. }
    10. return d + "Z";
    11. }

    Likewise, requiring “programmatically generated ticks” can be expressed with a loop instead of manual repetition:

    1. for (let i = 0; i < 60; i++) {
    2. const angle = (i / 60) * Math.PI * 2;
    3. // Generate minute ticks; hour ticks are longer when i % 5 === 0
    4. }

    During evaluation, also fix the runtime environment (same browser, same resolution, same interaction script); otherwise performance and visual conclusions are not reproducible.

    5. Real Constraints Beyond Capability: Context, Reasoning Pace, and Procurement

    Two points from the original discussion generalize into common experience. First, context window size directly affects the stability of long-file generation and cross-file refactoring. A wider window usually reduces “context anxiety” but introduces retrieval noise, so it needs to be paired with chunking and summarization strategies. Second, reasoning pace (whether explicit thinking is used and how long it is) changes response speed and output style: more concise reasoning is often faster but may skip self-checks under complex constraints; longer reasoning is more stable but sacrifices latency. In engineering, route by task tier: simple completions go through a low-latency path, while complex refactoring goes through a deep-reasoning path.

    On procurement, strip out brand factors and look only at generic categories. Individual developers care about whether a subscription and invoicing are available; enterprises care about team plans open for procurement, logging services, monitoring and alerting, and access management. Writing these as a checklist is more valuable than arguing about “which is better.”

    6. A Reproducible Evaluation Workflow

    1. Build 10–20 fixed tasks covering both open-ended and strong-constraint types;
    2. Define acceptance items and weights for each task to form a scoring sheet;
    3. Fix the runtime environment and interaction script, and run three times to take the average;
    4. Record failure types: missed constraints, runtime errors, messy structure, and performance degradation;
    5. Re-test once per quarter to observe capability drift from version updates.

    The conclusion matters less than the method. When evaluation is reproducible, metrics are decomposable, and constraints are decidable, “which model is better” naturally becomes “which model is more suitable for my task and budget.”