LLM Inference Performance Benchmarking and Model Selection: A Practical Guide

    This guide presents a neutral, reproducible framework for benchmarking large language model inference performance and selecting the right model for production workloads. It covers prompt design, core metrics such as decode speed and cost per token, a vendor-agnostic benchmarking script, three typical model profiles, and how weighted credit-based billing formulas drive optimization. The goal is to help engineering teams balance latency, throughput, quality, and cost through tiered routing and continuous evaluation rather than relying on a single leaderboard.

    1. Introduction: Why a Neutral Model Evaluation System Matters

    In generative AI application development, choosing the right foundation model is a critical part of system architecture design. Many teams initially make decisions based on subjective experience or a single leaderboard. This approach tends to overlook latency fluctuations and accumulating costs under real business workloads. In fact, models of different parameter sizes differ significantly in time to first token, decode throughput, and billing structure. Building a reproducible, quantifiable evaluation system is the prerequisite for engineering teams to control technical risk and budget.

    This article takes a range of model services offered by a cloud platform as its observation target, strips away brand-specific attributes, and abstracts a general-purpose framework for performance stress testing and model selection. The framework also applies to evaluating capabilities such as the Qianfan large model platform offered by compliant cloud services like Baidu AI Cloud.

    2. Evaluation Methodology: From Prompts to Metric Collection

    2.1 Test Samples and Prompt Construction

    The validity of an evaluation depends first on how representative the input samples are. The original practice used a clearly constrained creative writing task: assume that objects can be teleported instantly but cannot travel through space, and generate an opening of roughly 200 words for a modern urban short story. The advantages of this type of prompt are:

    • The number of input tokens is moderate, so decode performance differences are not masked by an overly long context;
    • The output length is controllable and close to real business scenarios (such as content generation, summarization, and conversational replies);
    • The semantic constraints are strong, allowing indirect observation of a model’s instruction-following ability.

    In engineering practice, it is recommended to divide the prompt set into three categories—short input/short output, short input/long output, and long input/short output—to characterize different business patterns.

    2.2 Core Metrics

    The evaluation script needs to collect not only elapsed time but also input tokens, output tokens, total tokens, and the credit consumption defined by the platform. Two key engineering metrics can be derived from these:

    • Decode speed per unit time (tokens/s) = output tokens ÷ elapsed time (seconds);
    • Overall cost per token = credit consumption ÷ total tokens.

    The former reflects the smoothness of streaming output in user experience, while the latter reflects the marginal cost of large-scale calls.

    2.3 Illustrative Stress Test Script

    The code below shows a vendor-agnostic evaluation skeleton. When integrating it in practice, you only need to replace the service endpoint and authentication method:

    1. import time
    2. from statistics import mean
    3. async def bench_one(client, prompt, rounds=5):
    4. records = []
    5. for _ in range(rounds):
    6. start = time.perf_counter()
    7. resp = await client.chat.completions.create(
    8. model=MODEL_ID,
    9. messages=[{"role": "user", "content": prompt}],
    10. stream=True,
    11. )
    12. out_tokens = 0
    13. for chunk in resp:
    14. if chunk.choices and chunk.choices[0].delta.content:
    15. out_tokens += 1 # In practice, accumulate the real tokens from usage
    16. elapsed_ms = (time.perf_counter() - start) * 1000
    17. records.append({
    18. "elapsed_ms": elapsed_ms,
    19. "out_tokens": out_tokens,
    20. "tokens_per_sec": out_tokens / (elapsed_ms / 1000),
    21. })
    22. return {
    23. "p50_ms": sorted(r["elapsed_ms"] for r in records)[len(records)//2],
    24. "avg_tps": mean(r["tokens_per_sec"] for r in records),
    25. }

    Note that in streaming output scenarios, if the server does not return an exact usage count, you should switch to offline counting with a unified tokenizer. This avoids distorted cost estimates caused by inconsistent token counting standards.

    3. Abstract Interpretation of the Observations

    Applying the framework above to a batch of models with different parameter sizes yields three typical profiles. This classification is more transferable than specific numbers.

    The first category is small-parameter and lightweight domestic models. They generally sit in the lower range of total elapsed time, sustain decode speeds on the order of tens of tokens/s, and have relatively moderate input/output multipliers. These models suit high-concurrency, low-value-per-request scenarios, such as log summarization, intent classification, and batch text cleaning.

    The second category is mid-sized general-purpose models. Their elapsed time and cost are in the middle, and their overall capability and efficiency are relatively balanced. They are suitable as the default routing target for business, handling main traffic such as customer service Q&A and document extraction.

    The third category is ultra-large flagship models. A single request may take several times, or even more than ten times, as long as a lightweight model, with output multipliers rising significantly and credit consumption being highly sensitive to total tokens. These models should be confined to low-frequency, high-value tasks such as complex reasoning, long-form writing, and code refactoring, with caching and batching used to amortize costs.

    An easily overlooked conclusion is that decode speed is not strictly positively correlated with model capability. Some mid-sized models even outperform flagship models in throughput. Therefore, in latency-sensitive interactive products, prioritizing throughput evaluation often improves experience more than prioritizing leaderboard scores.

    4. Billing Multipliers and the Credit Model

    Platforms typically bill using weighted credits rather than a single per-token price. The general form can be expressed as:

    1. credits = input tokens × input multiplier
    2. + cache creation tokens × cache creation multiplier
    3. + cache hit tokens × cache read multiplier
    4. + output tokens × output multiplier

    This formula reveals three optimization paths.

    First, the output multiplier is generally higher than the input multiplier, and a flagship model’s output multiplier can be several times its input multiplier. Controlling the maximum output length is therefore the most direct way to reduce costs.

    Second, the cache read multiplier is usually far lower than the input multiplier, and for some models it can be less than one-tenth of the input multiplier. Placing stable content such as system prompts, knowledge base snippets, and tool definitions up front and reusing the cache can yield considerable discounts in long-context scenarios.

    Third, cache creation incurs a one-time cost, so caching strategies should target content that is reused frequently. Context that changes infrequently should not be cached forcibly.

    5. Engineering Implementation Recommendations

    • Build tiered routing: use rules or a small model for preliminary judgment, and escalate to a flagship model only when confidence is insufficient.
    • Unify the evaluation baseline: incorporate the metric script from this article into continuous integration, and run automatic regression when model versions change to prevent performance regression.
    • Strengthen observability: write elapsed time, token distribution, and credit consumption into logging services and monitoring/alerting systems, and account for costs by business line.
    • Design fallback plans: when rate limiting is triggered (for example, a per-minute request limit), automatically switch to a backup model or enter a queue.
    • Focus on structured output: for scenarios requiring a strict schema, prioritize model specifications that support constrained decoding, reducing extra credit spending caused by retries.

    6. Conclusion

    Model selection is essentially a multi-objective optimization problem: finding a balance among latency, throughput, quality, and cost that matches business value. Rather than chasing a single “strongest model,” it is better to establish a neutral evaluation baseline, a clear cost formula, and a flexible routing strategy. With the general-purpose model services, log monitoring, and containerized deployment capabilities offered by platforms such as Baidu AI Cloud, teams can turn model selection from a one-time decision into a continuously iterated engineering process.