RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to benchmark token generation speed in tokens per second
HOW-TO · INF

How to benchmark token generation speed in tokens per second

intermediate·15 min·By Eruo Fredoline
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

Ollama or vLLM running with a model loaded

What this does

Extracts token-generation telemetry from the Ollama API response fields and computes a tokens-per-second figure for sustained throughput. After this guide a repeatable benchmark metric will be available for comparing quantization levels, hardware setups, or runtime parameters.

Steps

  1. Retrieve evaluation metrics from a non-streaming API call. The endpoint returns eval_count (output tokens) and eval_duration (time in nanoseconds) when streaming is disabled.

    curl -s http://localhost:11434/api/generate -d '{
      "model": "llama3:q4_K_M",
      "prompt": "Describe the water cycle in three sentences.",
      "stream": false
    }' > /tmp/response.json
    

    Expected output: No terminal output; JSON saved to file.

  2. Extract fields and compute tokens per second. Divides tokens by duration converted from nanoseconds to seconds.

    cat /tmp/response.json | jq '.eval_count / (.eval_duration / 1e9)'
    

    Expected output: A decimal number representing tokens per second, for example 18.4.

  3. Display raw fields for manual verification. Shows eval_count and eval_duration before trusting the calculation.

    cat /tmp/response.json | jq '{tokens: .eval_count, duration_sec: .eval_duration / 1e9}'
    

    Expected output: JSON with token count and duration in seconds.

  4. Run a batch to get stable aggregate figures. Averages multiple runs to smooth cold-start variance.

    for run in 1 2 3; do curl -s http://localhost:11434/api/generate -d '{"model":"llama3:q4_K_M","prompt":"Name three colors.","stream":false}' | jq -r '.eval_count / (.eval_duration / 1e9)'; done
    

    Expected output: Three numbers; average the last two for a stable result.

Verification

curl -s http://localhost:11434/api/generate -d '{"model":"llama3:q4_K_M","prompt":"Answer with exactly the word hello.","stream":false}' | jq '{tps: .eval_count / (.eval_duration / 1e9)}'
# Expected: JSON with "tps" key and a positive floating-point value

Common failures

  • eval_count or eval_duration missing - Streaming mode was used; set "stream": false.
  • zero tokens reported - Prompt may have been rejected by safety filters; check the response field for error messages.
  • extremely low TPS value - System may be under memory pressure or running on limited CPU cores; monitor resources during the run.
  • inconsistent results across runs - First run after model load is typically slower; always warm up and discard the first result.

Related guides

  • How to benchmark model response time using the Ollama API
  • How to run quantized models on systems with limited RAM
RELATED GUIDES
INF
How to benchmark model response time using the Ollama API
INF
How to run quantized models on systems with limited RAM
← All how-to guidesCourses →