Overview
llama-bench is a comprehensive performance testing tool for llama.cpp that measures inference speed, throughput, and resource utilization. It’s designed to help you optimize model configurations and compare performance across different settings.
Quick Start
Test Types
llama-bench performs three types of tests:
Prompt Processing (pp)
Measures how fast the model processes a prompt in batches.Text Generation (tg)
Measures token generation speed.Combined (pg)
Measures prompt processing followed by text generation.Command-Line Options
Basic Options
flag
Display help message and exit.
integer
default:"5"
Number of times to repeat each test for averaging.
integer
default:"0"
Delay between each test in seconds.
string
default:"md"
Output format:
md (markdown), csv, json, jsonl, or sql.string
Output format for stderr (same options as
-o).flag
Enable verbose output.
flag
Print test progress indicators.
Test Parameters
string
Path to model file. Can specify multiple models.Default:
models/7B/ggml-model-q4_0.ggufinteger
default:"512"
Number of prompt tokens for prompt processing test.
integer
default:"128"
Number of tokens to generate for text generation test.
string
Combined prompt processing and text generation test.Format:
pp,tg (e.g., -pg 512,128)integer
default:"0"
Context depth: prefill KV cache with this many tokens before testing.
Performance Options
integer
default:"2048"
Logical batch size.
integer
default:"512"
Physical batch size.
integer
Number of CPU threads. Can specify multiple values.
integer
default:"99"
Number of layers to offload to GPU.
string
default:"layer"
How to split model across GPUs:
none, layer, or row.boolean
default:"0"
Enable Flash Attention (0 or 1).
Usage Examples
Compare Different Models
Test Batch Size Impact
Test Thread Scaling
Test GPU Layer Offloading
Test Prefilled Context
Test performance with warm KV cache:Multiple Values & Ranges
You can specify multiple values in three ways:Comma-Separated
Multiple Flags
Ranges
Output Formats
Markdown (Default)
CSV
JSON
JSONL (JSON Lines)
SQL
Advanced Options
NUMA Configuration
Priority & Polling
integer
default:"0"
Process/thread priority:
0: Normal1: Medium2: High3: Realtime
integer
default:"50"
Polling level (0-100).
0 = no polling.Cache Types
f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1
Understanding Results
Tokens per Second (t/s)
The primary metric showing throughput:- Higher is better
- Format:
mean ± std_dev - Example:
120.60 ± 0.59means ~121 tokens/sec with low variance
Test Notation
- pp512: Prompt processing with 512 tokens
- tg128: Text generation of 128 tokens
- pp512 @ d512: Prompt processing at context depth 512
Important: llama-bench measurements do not include tokenization and sampling time. Real-world performance will be slightly lower.
Performance Analysis Tips
1
Baseline test
Run with default settings to establish baseline:
2
Identify bottlenecks
Test with different configurations:
- CPU vs GPU:
-ngl 0vs-ngl 99 - Batch sizes:
-b 128,512,2048 - Thread counts:
-t 4,8,16
3
Optimize settings
Find the sweet spot for your hardware:
- Balance GPU layers for your VRAM
- Adjust batch size for throughput vs latency
- Test Flash Attention:
-fa 0vs-fa 1
Comparing Quantizations
Benchmark different quantization levels:See Also
- llama-cli - Interactive CLI tool
- llama-perplexity - Quality measurement tool
- Performance Tips

