LLM Selection Guide: Quantitative Evaluation with Performance and Cost Metrics

    This guide explains how to evaluate large language models with measurable performance and cost metrics instead of relying on a single number. It covers how to define metrics such as end-to-end latency, token counts, output throughput, and unit cost; how to design reproducible benchmarks with fixed prompts and parameters; how to understand token-based billing models and calculate cost per request; and how to avoid common pitfalls when interpreting results. A sample Python script for collecting and summarizing request data is included.

    1. Why You Shouldn’t Select a Model Based on a Single Metric

    When choosing a large language model, you typically need to consider response speed, generation efficiency, and cost at the same time. Many teams look only at the unit price or only at leaderboard scores, and then run into latency fluctuations, unexpectedly high bills, or output quality that fails to meet business requirements in production. A sound approach is to break speed, throughput, and cost down into measurable metrics, compare them horizontally under identical test conditions, and then make a decision combined with task quality.

    2. Define Metrics First, Then Collect Data

    Before evaluation, standardize the definitions of your metrics so that different people are not using different criteria. It is recommended to include at least the following four categories:

    • End-to-end latency: the time from sending a request to receiving the complete response, measured in milliseconds.
    • Prompt tokens and completion tokens.
    • Output throughput (tokens per second): completion tokens divided by latency, reflecting generation speed.
    • Unit cost: the credits consumed by the request divided by the total token count, used for cross-model comparison.

    End-to-end latency consists of three parts: network round trip, server-side queuing, and generation. If the server provides time to first byte or queuing time, record these separately so you can distinguish the model’s own generation speed from external factors.

    3. Design a Reproducible Test Plan

    Whether your test conclusions are trustworthy depends on how well the experimental conditions are controlled. The following principles are recommended:

    1. Fix the prompts and task types. Use the same set of prompts, covering typical scenarios such as short-text rewriting, long-text comprehension, creative writing, and logical reasoning.
    2. Fix the output limit and sampling parameters. Unify max_tokens and temperature. Otherwise, differences in output length will directly distort the comparison of latency and cost.
    3. Repeat multiple times and analyze the distribution. A single result is easily affected by network and load jitter. Each sample group should contain no fewer than 20 runs, and you should pay attention to both the median and the p90 latency.
    4. Control concurrency and request rate. Services usually impose rate limits. During load testing, respect these limits to avoid throttled, failed requests polluting your statistics.

    The sample script below demonstrates how to collect data for a single request and aggregate the results. The script assumes the response body contains a usage field; the actual field names should follow the documentation of the API you are using.

    1. import os
    2. import time
    3. import statistics
    4. import requests
    5. BASE_URL = os.environ["LLM_BASE_URL"]
    6. API_KEY = os.environ["LLM_API_KEY"]
    7. HEADERS = {
    8. "Authorization": f"Bearer {API_KEY}",
    9. "Content-Type": "application/json",
    10. }
    11. def run_once(model: str, prompt: str, max_tokens: int = 512) -> dict:
    12. payload = {
    13. "model": model,
    14. "messages": [{"role": "user", "content": prompt}],
    15. "max_tokens": max_tokens,
    16. "temperature": 0.7,
    17. }
    18. start = time.perf_counter()
    19. resp = requests.post(BASE_URL, headers=HEADERS, json=payload, timeout=120)
    20. latency_ms = (time.perf_counter() - start) * 1000
    21. resp.raise_for_status()
    22. usage = resp.json()["usage"]
    23. return {
    24. "latency_ms": latency_ms,
    25. "prompt_tokens": usage["prompt_tokens"],
    26. "completion_tokens": usage["completion_tokens"],
    27. }
    28. def summarize(records: list[dict]) -> dict:
    29. latencies = [r["latency_ms"] for r in records]
    30. throughputs = [
    31. r["completion_tokens"] / (r["latency_ms"] / 1000) for r in records
    32. ]
    33. p90 = statistics.quantiles(latencies, n=10)[8]
    34. return {
    35. "median_latency_ms": statistics.median(latencies),
    36. "p90_latency_ms": p90,
    37. "median_tps": statistics.median(throughputs),
    38. }

    4. Understanding the Billing Model: From Tokens to Unit Cost

    Pay-as-you-go services usually split tokens by type and assign a different multiplier to each category. Common billing items include:

    • Regular input tokens;
    • Cache write tokens, i.e., context written for later reuse;
    • Cache hit tokens, i.e., the portion read when reusing cached context;
    • Output tokens.

    The general cost formula is as follows:

    Consumption = input tokens × input multiplier + cache write tokens × cache write multiplier + cache hit tokens × cache hit multiplier + output tokens × output multiplier

    The multiplier for output tokens is usually significantly higher than that for input tokens, so output length has a major impact on cost. Assume an input multiplier of 1 and an output multiplier of 4—these are demonstration values only, not the actual parameters of any service. If a request consumes 800 input tokens and 400 output tokens, the consumption is 800×1 + 400×4 = 2400. If another model compresses the output to 200 tokens, the consumption becomes 800×1 + 200×4 = 1600. This shows that controlling output length is often more effective than simply comparing unit prices.

    Multipliers and billing rules vary across services. Always refer to the official billing documentation, and make the multipliers configurable in your test script.

    5. Common Pitfalls When Interpreting Results

    • When output lengths differ, comparing latency directly is unfair. You should also report output tokens per second, or normalize by output length.
    • Fast does not mean good enough. Speed and cost tests must be paired with quality evaluation, for example through human review.