Evaluation Framework for Coding LLMs: Metric Design and Cost Calculation
This article introduces a reproducible evaluation framework for coding large language models (LLMs) to help teams select the most suitable model for their business needs. It details five evaluation dimensions with weighted metrics, specific test designs for 3D scene generation and front-end visual restoration, a comprehensive cost calculation method based on the cost per passed task, and actionable guidelines for implementation and model selection.
- Why Reproducible Evaluation is Necessary
Large language models (LLMs) have become an integral part of daily development workflows. Teams need to answer the question: which model best fits their business needs? Different models vary significantly in code generation, UI restoration, and 3D scene construction, and their API costs can differ by multiples. Relying solely on marketing materials or fragmented experiences can lead teams to choose models that are either overpowered and expensive, or underpowered, slowing down delivery.
Therefore, teams need a fixed set of test tasks, a unified scoring standard, and recorded cost data. With these, every model selection can be measured against the same yardstick, and conclusions can be re-validated after model upgrades.
- Evaluation Dimensions and Weights
The evaluation can cover five dimensions. The weights below are a suggested starting point; teams can adjust them based on business priorities, but any adjustments should be documented.
- Code Correctness (30% weight): Metrics include first-run pass rate and the number of passed boundary cases. The pass standard is that the code compiles and runs on the first try, with clear handling for empty inputs, oversized inputs, and anomalous inputs.
- Visual Restoration (20% weight): Metrics include layout, color scheme, spacing, and responsiveness, each scored from 0 to 5. The pass standard is an average score of at least 4 across the four items.
- Complex System Construction Capability (20% weight): Metrics include scene structure, lighting and shadows, interaction usability, and animation stability, each scored from 0 to 5.
- Contextual Consistency (15% weight): The metric is the preservation rate of original functionality after incremental modifications. The calculation is the number of original features still working normally after modification, divided by the total number of original features.
- Response Latency and Cost (15% weight): Metrics include first-token latency, generation speed, and cost per task. The cost calculation method is detailed in Part 5.
For each dimension, it is recommended to set 3 to 5 test cases ranging from easy to difficult, and use blind evaluation for scoring. Reviewers should not know the model’s identity to avoid bias.
- Test Design for 3D Scene Generation
The 3D generation test is used to verify the model’s spatial understanding capabilities. It is recommended to complete the test using two rounds of dialogue.
Round 1 Task: Construct a low-poly town with a day-night cycle effect using Three.js. The output should be a single HTML file that can be opened and run directly in a browser.
Round 2 Task: Add a rain weather effect while keeping the existing day-night toggle and camera settings unchanged.
During review, apply the following criteria: Is the scene structure clearly layered, with buildings, ground, and light sources managed in groups? Can the initial camera view capture the main content? Are the lighting and shadow parameters coordinated, without obvious shadow glitches? Is the animation loop smooth, without jumps? Are drag-to-rotate and zoom ready to use out of the box? After Round 2, calculate the original functionality preservation rate using the formula from Part 2.
Test records should include the model name and version, test date, temperature parameter, complete prompts, runtime environment (browser version and GPU model), and a scoring table for each item. Without these records, the conclusions cannot be reproduced by others.
- Test Design for Front-End Visual Restoration
The front-end test uses a fixed design description, such as a data dashboard containing three columns of data cards, and provides three breakpoints: 375px, 768px, and 1280px.
During review, refer to the following checklist: Does the page spacing generally use multiples of 8px? Are the colors derived from unified variable definitions rather than hard-coded values? Are there no more than 5 font-size levels, with distinguishable differences between levels? At 375px width, is there no horizontal scrollbar on the page?
Blind evaluation should be scored independently by two reviewers. If the score difference between the two exceeds 1 point, they should discuss and determine the result together.
Note that the visual effect of a static page only demonstrates the ability to generate visual drafts and does not directly represent production-level delivery capabilities. State management, API integration, error handling, and accessibility support require separate testing. The test report should separate these two types of conclusions.
- Cost Calculation Method
Cost calculation should be based on the total expenditure for completing a standard task, rather than just comparing the unit price per million tokens. More capable models usually require fewer correction rounds, so the total cost may not necessarily be higher.
It is recommended to use the following formula to calculate the cost per task:
Cost per task = (Number of input tokens × Input unit price + Number of output tokens × Output unit price) × Average correction rounds
The variables in the formula are defined as follows. The number of input tokens is the average input volume per request, including system prompts, historical context, and the current prompt. The number of output tokens is the average volume of generated content per round. The unit price is calculated per million tokens. The average correction rounds is the average number of API calls required to meet the acceptance standard, including the first round.
This formula assumes that the input and output volumes are the same for each round. If the context accumulates round by round, the input volume will increase continuously. In this case, the input volume of each round should be tracked separately and then summed.
Here is a hypothetical calculation example. Assume an input volume of 20,000 tokens, an output volume of 8,000 tokens, an input unit price of 2 currency units per million tokens, an output unit price of 8 currency units per million tokens, and an average of 2.5 correction rounds. The cost per task is (20,000 × 2 + 8,000 × 8) ÷ 1,000,000 × 2.5, resulting in 0.26 currency units. The above unit prices are for illustration only; actual selection should be based on the provider’s latest pricing.
To compare different models, teams should also calculate the cost per passed task, which is the cost per task divided by the task pass rate. Assuming the task pass rate in the above example is 80%, the cost per passed task is approximately 0.33 currency units. This metric reflects both cost and quality, making it more reliable than simply comparing unit prices.
- Implementation Guidelines
First, establish a team prompt template library. Each template needs to record its version, applicable tasks, and pass standards. The executor is the technical lead, updating it monthly.
Second, integrate static checks and test coverage thresholds into the Continuous Integration (CI) pipeline. For example, require zero linting errors and a unit test coverage rate no lower than the team’s set value. The executor is the development lead, and the artifact is a checklist that must be passed before merging a pull request.
Third, classify risk levels for tasks and configure models for each level. Low-risk tasks like code completion, page drafting, and unit test generation can use cost-effective models, backed by automated testing. High-risk tasks like architecture design and core algorithms should use flagship models with manual review. Routing rules are formulated by the technical lead and reviewed quarterly.
Fourth, conduct regular re-tests. Model versions update quickly, and the validity period of conclusions is usually short. It is recommended to re-test quarterly, or immediately when a provider releases a new version.
- Selection Conclusions
Scenarios suitable for cost-effective models include code completion, page drafting, and unit test generation. These tasks have a high fault tolerance and can be quickly verified through automated checks.
Scenarios requiring flagship models or human oversight include architecture design, core algorithms, and security-related code. The cost of errors in these tasks is high.
Cost comparison should be based on the cost per passed task. Looking only at unit prices can easily overestimate the actual cost of cheap models and underestimate the cost of models that require multiple correction rounds.
