Skip to content

llama-bench Guide: Benchmark Local LLM Speed in llama.cpp (2026)

6–9 minutes
Woman in a glass-walled office holding a tablet with a LLAMA-BENCH card, hook how fast is your LLM

Want to know how fast a local model really runs on your PC, or whether Q4_K_M or Q6_K, Vulkan or CUDA, 8 threads or 16 is quicker? llama-bench is the official benchmarking tool that ships with llama.cpp, and it answers those questions with repeatable numbers.

This guide shows how to install and run llama-bench, read its prompt processing (pp) and text generation (tg) results, test several models, quants, GPU layer counts, batch sizes and context depths in one command, and export results to CSV or JSON for comparison.

It follows the llama-bench README in the llama.cpp repository as of November 2026, including the newer options such as -hf downloads, -d context depth and --fit-target.

TL;DR

  • What: llama.cpp’s built-in speed test. Reports tokens per second (t/s) with a standard deviation.
  • Quick test: llama-bench -m model.gguf runs pp512 (prompt) and tg128 (generation) five times each.
  • pp vs tg: pp is how fast it reads your prompt; tg is how fast it writes the answer. tg is what you “feel” in chat.
  • Compare many settings at once: commas make a grid, e.g. -ngl 20,30,99 or -t 4,8,16.
  • Long-context speed: -d 0,8192 tests with the KV cache already filled.
  • Save results: -o csv, -o json, -o jsonl or -o sql.

What llama-bench Measures

llama-bench runs three kinds of tests:

Test Flag What it means
Prompt processing (pp) -p (default 512 tokens) How fast the model reads input: your prompt, documents, chat history
Text generation (tg) -n (default 128 tokens) How fast it writes new tokens, one by one
Prompt + generation (pg) -pg pp,tg A combined run, closer to a real request

Each test repeats five times by default (-r) and the tool prints the average tokens per second and the standard deviation. The README notes that tokenisation and sampling time are not included, so real apps can be slightly slower.

Prompt processing is mostly limited by raw compute, while text generation is mostly limited by memory bandwidth. That is why a GPU may show thousands of t/s for pp but “only” 100 t/s for tg.

Get llama-bench

  • Prebuilt: download a release zip for your backend (CUDA, Vulkan, Metal, CPU) from the llama.cpp releases page. llama-bench is included next to llama-cli and llama-server.
  • Build from source: cmake -B build (add -DGGML_CUDA=ON or -DGGML_VULKAN=ON for GPU) then cmake --build build --config Release. The binary is in build/bin/.

Running an AMD or Intel GPU? Our llama.cpp Vulkan guide shows how to get a GPU build working first.

Run Your First Benchmark

  1. Open a terminal in the folder that holds llama-bench.
  2. Run it on a local GGUF file: ./llama-bench -m models/qwen-7b-Q4_K_M.gguf
  3. Or let it download a model from Hugging Face: ./llama-bench -hf ggml-org/GLM-4.7-Flash-GGUF:Q4_K_M (it defaults to Q4_K_M when you leave the quant out).
  4. Wait for the warm-up and five repetitions of each test.
  5. Read the markdown table it prints.

On Windows the file is llama-bench.exe; run it from PowerShell or Command Prompt the same way.

How to Read the Results

A typical result from the README (Qwen2 7B Q4_K_M on an RTX 4080):

model size backend ngl test t/s
qwen2 7B Q4_K – Medium 4.36 GiB CUDA -1 pp512 7340.20 ± 23.45
qwen2 7B Q4_K – Medium 4.36 GiB CUDA -1 tg128 120.60 ± 0.59
qwen2 7B Q4_K – Medium 4.36 GiB CUDA -1 pp512 @ d512 6425.91 ± 18.88
qwen2 7B Q4_K – Medium 4.36 GiB CUDA -1 tg128 @ d512 116.71 ± 0.60
  • ngl -1 means all layers on the GPU (the default).
  • pp512 is prompt speed on 512 tokens; tg128 is generation speed for 128 tokens.
  • @ d512 means the test ran with 512 tokens already in the context. Speed drops as context grows.
  • ± value is the standard deviation. If it is large, close background apps and run again.

As a rough feel: under about 5 t/s generation feels slow, 10-20 t/s is comfortable reading speed, and 40+ t/s feels instant.

Test Many Settings in One Run

Almost every option accepts several values. Separate them with commas, repeat the flag, or give ranges. llama-bench runs every combination.

  • -n 16,32 or -n 16 -n 32: two generation lengths.
  • -ngl 10-40+10: 10, 20, 30, 40 GPU layers (range with step).
  • -b 128-1024*2: 128, 256, 512, 1024 (range with multiplier).
  • Several -m flags compare models or quants side by side.

Be careful: three values for four options means 81 combinations, each repeated five times. Start small.

Useful Benchmark Recipes

Compare quants of the same model

./llama-bench -m model-Q4_K_M.gguf -m model-Q5_K_M.gguf -m model-Q8_0.gguf -p 512 -n 128

Combine speed with the quality notes in our GGUF quantization guide to choose a file.

Find the best number of GPU layers

./llama-bench -m model.gguf -ngl 20,25,30,35,99

In the README’s 7B example, generation jumps from 71.76 t/s at 34 layers to 131.66 t/s once all 35 layers are on the GPU. The last few layers matter a lot.

Find the best CPU thread count

./llama-bench -m model.gguf -ngl 0 -t 4,8,12,16

On CPU, more threads stop helping past your number of physical cores; generation often peaks earlier than prompt processing.

Measure long-context slowdown

./llama-bench -m model.gguf -d 0,4096,16384 -fa on

Pair with KV cache types (-ctk q8_0 -ctv q8_0) to see how cache quantization affects speed.

Tune MoE offload

./llama-bench -m moe-model.gguf -ncmoe 0,8,16,24

-ncmoe keeps the expert weights of the first N layers on the CPU, which helps big mixture-of-experts models fit on smaller GPUs.

Compare backends or GPUs

./llama-bench --list-devices
./llama-bench -m model.gguf -dev Vulkan0/CUDA0

Use the device names from --list-devices. For multi-GPU systems, also try -sm layer vs -sm row and -ts tensor splits.

Most Useful Options

Option Default What it does
-p 512 Prompt length for pp tests (0 to skip)
-n 128 Tokens to generate for tg tests (0 to skip)
-d 0 Context depth (prefilled tokens)
-r 5 Repetitions per test
-ngl -1 (all) Layers offloaded to GPU
-t System dependent CPU threads
-b / -ub 2048 / 512 Logical and physical batch size (affects pp speed)
-fa auto Flash attention on, off or auto
-ctk / -ctv f16 KV cache type for keys and values
-sm layer Multi-GPU split mode: none, layer, row, tensor
-fitt off Fit the model to device memory with a margin in MiB
--progress off Show progress during long runs
--delay 0 Seconds to wait between tests (lets GPUs cool)

Export Results (CSV, JSON, SQL)

Markdown is the default. For spreadsheets or scripts, choose another format:

  • -o csv: one row per test with build commit, CPU, GPU, backend, model and every setting, plus average and stddev t/s.
  • -o json or -o jsonl: the same data, including each individual repetition.
  • -o sql: SQL insert statements you can load into SQLite.
  • -oe md: print a readable table to stderr while CSV/JSON goes to stdout.
./llama-bench -m model.gguf -o csv > results.csv

Because the CSV includes the build number and hardware, it is great for tracking speed across llama.cpp updates.

How to Benchmark Fairly

  1. Close games, browsers with hardware acceleration and other AI apps (Ollama, LM Studio).
  2. Plug in laptops and use a performance power plan.
  3. Keep the warm-up on (do not use --no-warmup) and use at least 5 repetitions.
  4. Change one thing at a time: model, quant, layers, threads or backend.
  5. Note your llama.cpp build number; speed changes between releases.
  6. Test at a context depth that matches your real use with -d.

If your speeds look low inside Ollama, see our Ollama slow fix guide; for serving many users, compare engines in vLLM vs llama.cpp vs Ollama.

Troubleshooting

Problem Fix
Backend column says CPU You have a CPU-only build; download or build a CUDA, Vulkan or Metal version
Out of memory Lower -ngl, use a smaller quant, reduce -d, or try -fitt 512
Huge ± values Background load or thermal throttling; close apps, add --delay 5
Default model not found Always pass -m or -hf; the default path is a placeholder
Run takes forever Too many combinations; reduce values or -r, add --progress
Results differ from llama-server Bench skips tokenisation and sampling, and servers add overhead; compare relative numbers
Gated Hugging Face model fails Set HF_TOKEN or pass -hft

FAQ

What is a good tokens per second for local LLMs?

For chat, 10-20 t/s generation is comfortable and 40+ feels instant. Prompt processing should be in the hundreds or thousands on a GPU.

What is the difference between pp512 and tg128?

pp512 measures reading a 512-token prompt; tg128 measures writing 128 new tokens. tg is closer to what you feel when chatting.

Can llama-bench test Ollama models?

It needs a GGUF file. Ollama stores models as GGUF blobs, but it is simpler to download the same GGUF from Hugging Face with -hf.

Does llama-bench include sampling time?

No. Tokenisation and sampling are excluded, so it measures raw model speed.

How do I benchmark long context?

Use -d, for example -d 0,8192,32768, to prefill the KV cache before each test.

How do I compare two GPUs?

List them with --list-devices and run once per device with -dev, or use -sm and -ts to test splitting.

Can I share my results?

Yes. -o csv or -o json includes your CPU, GPU, backend and build, which makes results easy to compare with others.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a glass-walled office holding a tablet with a LLAMA-BENCH card, hook how fast is your LLM