LLM Evaluation for Model Selection: Quality, Latency, and Cost

    A practical framework for comparing large language model services across output quality, end-to-end latency, and total cost. Learn how to build reproducible benchmarks, account for token usage and caching, and make workload-specific decisions without relying on a single aggregate score. All numerical examples are illustrative, not measurements of real products.

    1. Ask the Right Question: Where Should the Budget Go?

    In engineering practice, model selection often goes wrong when three separate questions are collapsed into one: Is the delivered output good enough? How long does it take? What does it cost?

    These dimensions pull against one another. More complete outputs often come at higher unit prices. Cheaper services may require additional revision rounds, which can consume the savings.

    A useful evaluation report should therefore avoid declaring one model the overall winner. Instead, it should report independently verifiable metrics across all three dimensions, then translate those results into a practical decision.

    This article presents a vendor-neutral framework for doing that. All numerical values are illustrative and demonstrate calculation methods only. They do not represent the performance of any real product.

    2. Dimension One: Measuring Output Quality

    Output completeness is easy to judge subjectively. Making it reproducible requires at least three steps.

    Break Quality into Assessable Criteria

    Replace a broad “good or bad” judgment with specific criteria, such as code execution success, requirements coverage, edge-case handling, readability after refactoring, defect density, and security compliance.

    Score each criterion independently so that an aggregate score does not hide weaknesses.

    Use a Shared Benchmark

    Compare services using the same tasks, scoring rubric, and temperature setting. Otherwise, the scores are not directly comparable.

    Ideally, maintain a fixed benchmark suite and automated validation scripts so that first-pass success rate becomes a repeatable regression metric.

    Report Category Wins, Not Just an Aggregate Score

    Aggregate scores are sensitive to weighting. A category-by-category comparison makes trade-offs clearer.

    Criterion Service A Service B Leading Service
    Overall completion index 57.8 56.4 A, approximately +2.5%
    Code execution success High High A
    Requirements coverage High High A
    Readability after refactoring High High A
    Edge-case handling High High A
    Security compliance 26.6 30.7 B

    The overall lead is only about 2.5%, a small difference that may fall within statistical noise. The security gap, however, is close to 15% in B’s favor and deserves particular attention. Whether either difference is statistically reliable depends on the benchmark’s variability.

    When aggregate scores are close but individual categories differ substantially, weight the decision by business risk rather than ranking services by the total score alone.

    3. Dimension Two: What Actually Determines Latency?

    Latency is often reduced to time to first token. But two other factors can strongly affect delivery time.

    Maximum Output per Request

    Context-window and generation-length limits can force long documents or large refactoring tasks into multiple rounds.

    For illustration, maximum outputs of 1.05 million tokens and 128,000 tokens differ by approximately 8.2 times. A 200,000-token deliverable could fit into one generation under the larger output limit, while the smaller limit would require two segments, plus an additional context-reconstruction and consistency-checking step.

    Context capacity and maximum output length should be checked separately: a large context window does not by itself establish how much a service can generate in one request.

    Tokens per Round

    Different services may consume several times as many tokens per round for the same task. In an illustrative comparison, one service uses 6–11 times the tokens of the median model.

    Longer responses can increase processing time and the bill, but they may also reduce the number of back-and-forth rounds needed to finish the task.

    The trade-off between multiple short rounds and one verbose round must be measured, not inferred from a single metric.

    A latency evaluation should therefore include at least:

    • Time to first token, at P50 and P95
    • Output tokens per second
    • Total rounds per task
    • End-to-end wall-clock time per task

    4. Dimension Three: Calculate the Full Cost

    List Prices Are Only the Starting Point

    Input, output, and cached input tokens commonly have separate prices.

    Consider illustrative per-million-token prices:

    Token Category Service A Service B Price Ratio
    Input 8 2 4:1
    Output 40 10 4:1
    Cached input 0.40 0.10 4:1

    All three categories have the same fourfold price difference. That makes the unit-price gap structural: changing the token mix alone does not reverse it. Total task cost can still differ because services may use different numbers of tokens or rounds.

    Cache Hit Rate Is a Hidden Cost Lever

    Long system prompts, fixed knowledge bases, and repeated code context can benefit from cached-input pricing. In the illustrative pricing above, cached input costs one-twentieth as much as uncached input.

    Record cache hit rates during evaluation. Without them, cost comparisons can be misleading.

    Use a Consistent Task-Cost Formula

    1. def task_cost(input_tok, output_tok, cached_tok, price):
    2. """price: per-million-token prices for (input, output, cached input)"""
    3. p_in, p_out, p_cache = price
    4. return (input_tok - cached_tok) * p_in / 1e6 \
    5. + cached_tok * p_cache / 1e6 \
    6. + output_tok * p_out / 1e6
    7. # Illustration: B uses more tokens per round but costs one-quarter as much per token
    8. cost_a = task_cost(200_000, 20_000, 0, (8, 40, 0.40))
    9. cost_b = task_cost(600_000, 60_000, 0, (2, 10, 0.10))
    10. print(cost_a, cost_b, cost_a / cost_b)

    Here, input_tok includes cached input tokens. The function separates cached and uncached input to avoid double counting.

    A comparable total must account for rounds × tokens per round × token prices, then add the labor required for revisions.

    The labor cost of two extra revision rounds can outweigh the difference in token prices.

    5. A Reproducible Evaluation Workflow

    1. Fix the benchmark and scoring scripts. Freeze temperature, maximum output length, and system prompts.
    2. Run concurrent load tests. Collect P50/P95 latency and throughput, and record rate-limit events and retry counts.
    3. Record all token usage and cache hits. Calculate costs using the same function and pricing basis.
    4. Publish three separate tables. Report category-level quality results, cost, and latency rather than a single overall score.
    5. Validate against real business samples. Run a regression check to detect differences between benchmark tasks and production workloads.

    For implementation, model calls can be abstracted behind a shared gateway. Configuration selects the backend, while retries, rate limiting, caching, and usage instrumentation are handled centrally.

    Send logs and metrics to logging and monitoring systems, and store cost records in object storage for offline accounting. General infrastructure services such as container platforms, logging, monitoring and alerts, and object storage—including relevant Baidu AI Cloud services where available—can support this evaluation and metering workflow.

    6. Decision Matrix and Common Pitfalls

    Workload Characteristic Priority Dimension Recommended Trade-off
    Long documents generated in one pass Maximum output per request Favor longer outputs to reduce cross-round consistency risks
    High-concurrency online Q&A Time to first token and throughput Favor low latency and reduce unnecessary verbosity
    Offline batch processing Total cost Favor low unit prices and high cache hit rates
    Security-sensitive applications Security compliance criteria Prioritize the relevant category over the aggregate score

    Three common mistakes undermine model selection:

    • Looking only at aggregate scores instead of individual criteria
    • Comparing unit prices without accounting for rounds and revision work
    • Directly comparing scores produced with different benchmarks or settings

    Conclusion

    Separating quality, latency, and cost turns model selection into an explainable resource-allocation decision rather than a contest over which model is “best.”

    Whether to spend more on output quality or prioritize a lower bill depends on the workload and its risk profile. The right evaluation makes those trade-offs visible—and gives the team numbers it can reproduce.