Sub topic 15
Measuring real speed with llama-bench
This chapter assumes you can run commands in a terminal, have a GGUF file on disk, and have read the earlier chapters on memory bandwidth, the tokens-per-second ceiling, and partial GPU offload. It also assumes you have built or installed llama.cpp, which includes the llama-bench tool.
Why measure
The ceiling from the previous chapters is an upper bound. Real speed is lower because of runtime overhead, cache effects, and how well the software uses your hardware. A measurement tells you how far below the ceiling you are, and it gives you a baseline for comparing quantisation levels or offload settings.
Running the benchmark
llama-bench runs two tests. The prompt test (-p) feeds in a fixed number of tokens and measures prompt processing speed. The generation test (-n) produces a fixed number of tokens and measures generation speed.
llama-bench -m model-Q4_K_M.gguf -p 512 -n 128 -ngl 99The flags mean:
-mis the model file.-p 512processes a 512-token prompt.-n 128generates 128 tokens.-ngl 99offloads up to 99 layers to the GPU. Any number at or above the model's layer count offloads everything.
The output is a table. Each test appears as a row, with a name such as pp512 for prompt processing or tg128 for token generation. The last column gives tokens per second, with a standard deviation from repeated runs.
Reading the numbers
Compare the tg figure with your ceiling. With 100 GB/s of bandwidth and a 4.9 GB file, the ceiling is about 20 tokens per second. A result of 14 to 18 is typical. A result of 3 usually means something is wrong.
The pp figure is normally much higher than tg, often by ten times or more. Prompt processing handles many tokens at once and depends more on compute than on bandwidth, so the two numbers measure different limits.
Common errors
| Symptom | Likely cause |
|---|---|
| `tg` far below the ceiling | Too few layers offloaded, or the model spilled out of VRAM into system RAM |
| Speed drops sharply when you raise `-ngl` | VRAM is full, so the driver swaps data over a slower link |
| Results vary between runs | Other programs are using the GPU or CPU, or the machine is throttling from heat |
| `pp` and `tg` are both low | The binary was built without GPU support |
Comparing settings
Change one variable at a time. Run the same model at several -ngl values, such as 0, 20, and 99, and note where the tg figure stops improving. You can also benchmark two quantisation levels of the same model and compare speed against the quality trade-offs from earlier chapters.
Exercise
A GPU has 200 GB/s of memory bandwidth and your model file is 5 GB. llama-bench reports tg128 of 9 tokens per second with -ngl 99. What is the ceiling, and what should you check first?
Show answer
The ceiling is 200 / 5 = 40 tokens per second. The measured 9 is far below it. Check first whether the model and its KV cache actually fit in VRAM, because spilling into system RAM would explain the gap. Then confirm the build has GPU support and that no other program is using the GPU.