400 Tokens per Second for Code Generation: How to Measure and Apply It in Practice
A claimed 400 tokens per second is only meaningful when its measurement conditions are clear. This article explains how to verify throughput claims, understand the system optimizations behind faster inference, design a fair web-generation benchmark, and safely handle high-speed streaming output in production code.
A model provider recently introduced a high-speed API variant that claims output speeds of up to 400 tokens per second. The industry has long assumed that faster models are less capable, while the provider says this accelerated version of its flagship model retains strong coding performance.
Developers need to answer three questions:
- Can the claimed performance be verified?
- Which technologies contribute to the speed increase?
- Can higher throughput translate into measurable productivity gains in real projects?
This article addresses these questions in order and provides a streaming-output code example along with a practical testing checklist.
1. Which Performance Numbers Can Be Verified?
400 tokens per second is a vendor-provided claim. The measurement conditions—such as input length, concurrency, whether time to first token is included, and which tokenizer is used—are not always fully disclosed in promotional materials. Without this information, the figure should be treated only as a reference result under a specific set of conditions.
Leaderboard scores also require verification. The original claim states that the model scored 1,532 points in a coding arena, exceeding a previous model’s score of 1,524. Leaderboard scores can change as new models are added and evaluations are rerun. Before comparing results, verify the leaderboard name, measurement date, and model version.
The claimed “eightfold time difference” does not include enough information about the test environment, model name, prompt, or measurement method. This article does not use that figure.
The basic conversion is straightforward: at 400 tokens per second, 0.3 seconds corresponds to approximately 120 output tokens. A blink typically lasts between 0.1 and 0.4 seconds, depending on the person and situation. This conversion is valid only when the output speed remains stable and network queueing time is excluded.
2. Acceleration Technologies and Their Limits
Inference speed usually improves through several system-level optimizations. No single technology can fully explain the overall result. The following three approaches are common in the industry, and each has specific prerequisites and limitations.
2.1 Speculative Decoding
A smaller draft model predicts several upcoming tokens first. The larger model then verifies those predictions in parallel. Tokens that pass verification can be accepted in batches, reducing the number of sequential generation steps performed by the larger model.
Its limitations include:
- The draft model must be well matched to the primary model. After the primary model is updated, the effectiveness of speculative decoding must be reevaluated.
- Rejected draft predictions create additional computation. When the acceptance rate is low, performance may stay the same or even decline.
- At higher sampling temperatures, the draft model’s predictions are less likely to match the primary model, reducing the acceptance rate.
- Highly templated code may be easier to predict correctly in theory, but this must be validated with real workloads.
2.2 PagedAttention and KV Cache Optimization
PagedAttention manages GPU memory in pages, reducing fragmentation and allowing the same GPU to serve more concurrent requests.
This type of optimization primarily improves server-side throughput. It may not significantly improve an individual user’s time to first token or single-stream generation speed. The main user-visible benefit may instead come from reduced queueing time.
2.3 Infrastructure
High-bandwidth networking and multi-GPU interconnects can overlap computation and communication, reducing idle time while data is transferred.
Developers generally cannot control these resources directly. They can influence the results indirectly by selecting the service region, service tier, and available concurrency quota.
3. How to Compare Models in a Web-Generation Test
A suitable benchmark task is to generate a personal blog page from scratch. The page should include a navigation bar, article cards, and a habit-tracking dashboard.
Both model versions should use the same prompt, temperature, and maximum output length. The following table lists recommended measurement methods and the conditions that must be reported.
| Metric | Recommended measurement | Conditions to record |
|---|---|---|
| Output speed | Number of output tokens divided by the time from the first token to completion | Full model name and version, API type, region |
| Time to first token | Time from request submission to receipt of the first token | Network environment, concurrency |
| End-to-end latency | Time from request start until all code has been generated | Prompt, temperature, max_tokens |
| Artifact usability | Whether the page renders, whether the console reports errors, and whether key interactions work | Checklist version, reviewer |
| Code quality | Number of defects found in each version | Defect criteria |
The following practices are also important:
- Repeat each test at least five times and report the median rather than a single result.
- Use the tokenizer specified in the official documentation when counting tokens. Results from different tokenizers cannot be compared directly.
- Record the timestamp and network conditions for every test so the results can be reviewed later.
- Do not claim that one model is “X times faster” before all relevant conditions have been documented. A more defensible statement is: “Under these conditions, the model was approximately X times faster,” followed by the test details.
4. Engineering for High-Speed Streaming Output
When streaming output arrives faster than an editor can render it, code may appear to scroll down the screen in a waterfall-like stream. Developer tools need to buffer the output and handle data boundaries correctly.
The example below addresses several common implementation problems:
- Calling
decodeindependently on every data chunk can split a multibyte UTF-8 character, causing decoding errors or corrupted text. - Without timeouts, authentication, and retries, network instability can cause the request to hang or fail.
- An undefined push function makes the example impossible to run directly.
import asyncioimport codecsimport osimport aiohttpAPI_URL = "https://api.example.com/v1/codegen" # Replace with the endpoint in the official documentationAPI_KEY = os.environ["CODEGEN_API_KEY"] # Read the key from an environment variable; do not store it in code or logsBUFFER_THRESHOLD = 1024 # Character count
