Skip to content

Blog · Generative AI ·

llama.cpp vs Ollama: which is faster? Measured on a 6 GB laptop GPU

By Khadim Hussain · 4 min read

In short

On the same GGUF files and the same 6 GB RTX 4050 laptop, llama.cpp generated text 2-7% faster than Ollama and read the prompt 6-29% faster whenever the whole model sat on the GPU. The big gaps came from where each tool put the model, not from the engines: Ollama split Llama 3.1 8B 25%/75% between CPU and GPU and wrote 25.6 tokens per second, while llama.cpp with every layer on the GPU wrote 38.5. On the mixture-of-experts gpt-oss-20b it went the other way: Ollama's own split gave 33.5 tokens per second out of the box, and llama.cpp only matched it (34.0) after I tuned --n-cpu-moe.

Contents

I ran the same model files through llama.cpp and Ollama on one laptop to see whether the choice of tool changes the speed. When a model fits on the GPU, it barely does. When it doesn't, the tool's decision about which parts go to the GPU matters far more than the engine.

The laptop: an RTX 4050 Laptop GPU with 6 GB (at a 60 W power limit, with about 1.7 GB already held by the Windows desktop), a Core i7-13620H and 32 GB of DDR5, on Windows 11. Versions: llama.cpp b12728 (CUDA build) and Ollama 0.40.16. Every number below is mine; the full rows are on the RTX 4050 Laptop benchmark page.

Is llama.cpp faster than Ollama?

Slightly, when the whole model is on the GPU. I imported each GGUF file into Ollama unchanged, so both tools ran the same weights at the same quantization, and Ollama reported 100% GPU for all six:

Model (Q4)Generation, llama.cpp (tok/s)Generation, Ollama (tok/s)Prompt, llama.cpp (tok/s)Prompt, Ollama (tok/s)
LFM3 1.7B142.9132.38,1046,475
Hy-MT3 1.8B117.7110.07,5366,438
Llama 3.2 3B Instruct83.480.34,4434,166
Gemma 3 4B it62.960.93,7692,682
Spark-X2.6 4B56.952.73,2412,396
Nemotron 3.5 Bolt E4B45.844.74,1543,168

Ollama wrote 2-7% fewer tokens per second and read the prompt 6-29% slower. You won't feel 5% while chatting. The prompt gap is more noticeable with long inputs, such as a coding agent sending a large file.

Why was Ollama 50% slower on Llama 3.1 8B?

Because it kept a quarter of the model off the GPU. Llama 3.1 8B at Q4_K_M is a 4.91 GB file, close to what a 6 GB card has free once Windows takes its share. ollama ps showed the split Ollama chose: 25%/75% CPU/GPU. The Ollama FAQ explains that figure: the model "was loaded partially onto both the GPU and into system memory."

llama.cpp lets you choose the number of layers on the GPU with -ngl, so I ran it three ways:

SetupGeneration (tok/s)Prompt (tok/s)
Ollama, its own split (25%/75% CPU/GPU)25.6979
llama.cpp, 24 layers on the GPU25.81,053
llama.cpp, 28 layers on the GPU29.81,326
llama.cpp, all layers on the GPU38.51,852

With 24 layers on the GPU, llama.cpp landed on Ollama's number, which suggests that's roughly where Ollama stopped. Putting every layer on the card made generation 50% faster and the prompt nearly twice as fast.

One caution before you copy that. My test used a 512-token prompt and 128 new tokens, which needs little memory for the context. A long conversation needs more, and an all-on-GPU setup can run out of memory where a more cautious split keeps going.

When was Ollama the faster one?

On gpt-oss-20b, a mixture-of-experts model whose MXFP4 file is 12.1 GB, twice the card's memory. Most of it has to live in system memory, and the question is which parts. llama.cpp's --n-cpu-moe N keeps the expert weights of the first N layers on the CPU (its documentation describes it that way), so the shared parts stay on the GPU:

SetupGeneration (tok/s)Prompt (tok/s)
Ollama, its own split (67%/33% CPU/GPU)33.5271
llama.cpp, --n-cpu-moe 1212.889
llama.cpp, --n-cpu-moe 1834.0422
llama.cpp, --n-cpu-moe 2430.1351

My first guess, 12, tried to hold too much on a 6 GB card and ran at 12.8 tokens per second, a third of Ollama's speed. At 18 llama.cpp matched Ollama on generation and read the prompt 56% faster. Ollama got there with no tuning at all.

How did I measure?

  • llama.cpp: llama-bench -p 512 -n 128 -r 3 -d 0,4096, flash attention on auto, default batch. The tables use the empty-context rows (-d 0).
  • Ollama: the same GGUF imported with a Modelfile, one warm-up call, then three timed calls with a ~512-token prompt and 128 new tokens. Each prompt starts with a fresh random prefix, so Ollama's prompt cache can't skip work. I recorded ollama ps for the split.
  • One model at a time, one user. The method page has the rest: how the benchmarks are measured.

Which should you use?

If youUseWhy, from these runs
Want a model running in minutes, with an API other apps already speakOllamaWithin 2-7% of llama.cpp on anything that fits
Run a mixture-of-experts model bigger than your GPUOllama, or llama.cpp with --n-cpu-moe tunedOllama's own split matched llama.cpp's best one
Have a dense model that almost fits, and short promptsllama.cpp with more layers on the GPUUp to 50% faster than Ollama's split on Llama 3.1 8B
Paste long files into the prompt, as coding agents dollama.cppRead prompts 6-29% faster, up to 89% with all layers on the GPU

If you're picking hardware rather than software, the local LLM hardware comparison covers GPUs, Macs and the DGX Spark. If you want Ollama behind Claude Code on Windows, that setup is here.

What this doesn't cover

One laptop GPU, one user, short prompts. I haven't measured LM Studio, vLLM, AMD or Apple hardware with this pair yet, or long-context runs. The per-model pages (Llama 3.1 8B, gpt-oss-20b) show how other devices do on the same models.

Next

Frequently asked questions

Is llama.cpp faster than Ollama?

A little, when the model fits on the GPU: on my RTX 4050 laptop llama.cpp generated 2-7% faster and read the prompt 6-29% faster, on the same GGUF files. When a model doesn't quite fit, the gap depends on how much of it each tool keeps on the GPU, and that can swing 50% either way.

Why is Ollama slow on my GPU?

Run ollama ps while the model is loaded. If it says something like 25%/75% CPU/GPU, part of the model is in system memory and every token waits on the CPU. On a 6 GB card that cost Llama 3.1 8B a third of its speed: 25.6 tokens per second in Ollama against 38.5 in llama.cpp with all layers on the GPU.

How do I control how much of the model goes on the GPU?

In llama.cpp, with -ngl (layers on the GPU) and, for mixture-of-experts models, --n-cpu-moe N, which keeps the expert weights of the first N layers on the CPU. Ollama decides the split itself and shows it in ollama ps; its Modelfile and FAQ pages document no setting to change it.

Should I use Ollama or llama.cpp?

Ollama if you want models running in minutes and an API other tools already speak; on a mixture-of-experts model it placed the weights better than my first llama.cpp guess. llama.cpp if you're squeezing a model into a small GPU and are willing to try a few settings: it was never slower once tuned.

Is LM Studio faster than Ollama?

I haven't measured LM Studio yet, so I can't say. This comparison covers llama.cpp and Ollama on one laptop GPU.

Want a second pair of eyes on this?

Book a 15-minute intro call. Bring the problem, and you leave with a concrete next step.