Backprop Bulletin practical guide
Run a small language model locally and measure its speed and memory use
Before you build on a model that runs on your own computer, you need three numbers: how long it takes to start answering, how fast it writes, and how much memory it holds. This guide gives you a small meter that measures all three for any model program. You check the meter first against a simulated model whose behaviour is known, then use it on a real open-weight model with llama.cpp.
What you will build
The meter is one file, measure-model.mjs. You give it the command that runs a model, and it starts that program, watches it and reports:
- Time to first output: how long from starting the program until it first writes anything. For a model run from the command line, this includes loading the model and reading your prompt.
- Generation rate: how fast the rest of the answer arrives after that first output.
- Peak memory: the most memory the program held at once, as Linux reports it.
It works in two ways. In output mode, it measures any program that prints generated text. In server mode, it starts a model server such as llama.cpp's llama-server, waits until the model is loaded, sends one request and times the answer as it streams back. Server mode separates loading time from answering time, and it uses the server's own count of tokens, the units a model generates.
The same file contains a simulated model: a few lines of code with a fixed loading time, a fixed pace and a fixed amount of memory. It is not a language model. It exists so that you can see the meter read a target whose true values you know before you trust the meter with a real model.
Prerequisites and tested runtime
- Linux. The meter reads memory figures from the Linux
/procfile system, so it does not work on macOS or Windows. - Node.js 20 or later, with no packages and no build step. Tested with Node.js 24.22.1 and 22.23.5 on Linux, in Bash; the output shown here was the same on both.
- About 0.3 GB of free memory for the simulated model. A real model needs more: at least the size of its model file, plus room for the program around it.
- An empty folder. The meter writes no files. In server mode it talks only to the server it started, on your own computer (127.0.0.1).
Create an empty folder, open a terminal in it and download the meter into it:
Download measure-model.mjs JavaScript, 398 lines, 19.7 kB
Before running a downloaded file, read it. You can also check that you have the same file this guide was tested with:
Run
sha256sum measure-model.mjs
Expected output
289c52216765fc8682d2aeaafc29550b32c4ed45ead288351166fca5b1726852 measure-model.mjs
How the meter measures
Time
The meter notes the time on Node.js's high-resolution clock just before it starts the program, and again each time output arrives:
child.stdout.on("data", (chunk) => {
const t = performance.now();
first ??= t;
last = t;
reads += 1;
Time to first output is the first of those times minus the start. The rate is the number of words after the first, divided by the time from the first output to the last. In output mode the meter counts words, because it cannot know how a program splits text into tokens. If the whole output arrives in fewer than five reads, or within a tenth of a second, the meter does not report a rate at all, because there is nothing to time:
if (reads < 5 || span < 100) {
Memory
Linux publishes each process's memory use in /proc/<pid>/status. The meter reads it every 0.1 s while the program runs:
function readStatus(pid) {
let text;
try { text = readFileSync(`/proc/${pid}/status`, "utf8"); } catch { return null; }
const kb = (field) => Number(new RegExp(`^${field}:\\s+(\\d+) kB`, "m").exec(text)?.[1]);
const s = { rss: kb("VmRSS"), hwm: kb("VmHWM"), anon: kb("RssAnon"), file: kb("RssFile") };
return Number.isFinite(s.rss) ? s : null; // a process that has just exited has no memory lines left
}
Three of those fields appear in the report. VmRSS is the resident set size: the memory the process holds in RAM right now. VmHWM is its peak, the "high water mark", which the kernel keeps itself, so a brief peak between two of the meter's readings is not lost. RssFile is the part of the resident memory that maps files. A model file that a program maps into memory, rather than reading into memory it allocated itself, is counted there.
The meter also looks for processes that the measured program started, using the parent process number that Linux records for every process. Their memory is not counted, and the report says so:
if (stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1] === String(pid)) found.push(Number(name));
Server mode
With --server, the meter picks a free port, puts it where your command has {port}, starts the server and asks GET /health every 20 ms. llama.cpp documents that this answers 503 while the model is loading and 200 when the server is ready:
if ((await call(port, "GET", "/health")).status === 200) readyAt = performance.now();
Then it sends one chat completion with streaming turned on, in the OpenAI-compatible form that llama-server accepts, and asks for the token count at the end of the stream:
model: "local", messages: [{ role: "user", content: opts.prompt }], max_tokens: opts.maxTokens, temperature: 0, stream: true, stream_options: { include_usage: true },
If the server reports a count, the rate uses it; if not, the meter counts the pieces of text that arrived instead, and says so:
const tokens = Number.isInteger(reported?.completion_tokens) ? reported.completion_tokens : pieces;
When the answer is complete, the meter stops the server with SIGTERM.
Rounding
The report rounds times to 0.1 s, rates to whole numbers and memory to 0.1 GB, and shows anything smaller as "under 0.1 GB". One run on a busy computer varies by more than finer figures would suggest. Add --precise to see milliseconds, megabytes and two decimal places.
Check the meter on a simulated model
The simulated model's behaviour is set by one line:
const SIM = { loadMs: 1250, everyMs: 100, firstTokenMs: 250, megabytes: 250, words: 49 };
It "loads" for 1.25 s, during which it fills a 250 MB block of memory, standing in for model weights. Writing to every byte makes the memory really resident, not just reserved:
return Buffer.allocUnsafe(SIM.megabytes * 1e6).fill(0x5a);
Then it prints one word every 0.1 s, 49 words in all. In server mode it answers /health with 503 until 1.25 s have passed, and streams its first token 0.25 s after each request. When the meter starts it, the meter passes its start time in the MEASURE_MODEL_STARTED environment variable, so the simulated schedule counts from that moment, including Node.js's own start-up. Other programs ignore the variable.
First, see what the simulated model prints. Twelve words take about 2.4 s:
Run
node measure-model.mjs simulate --words 12
Expected output (simulated model)
This text comes from the simulated model in measure-model.mjs. It is not
Now measure it in output mode. Everything after -- is the command being measured:
Run
node measure-model.mjs measure -- node measure-model.mjs simulate
Expected output (simulated model)
measured: node measure-model.mjs simulate
exit status: 0
time to first output: 1.3 s (includes start-up and loading)
output: 49 words; output begins: "This text comes from the simulated model in ..."
output rate: 10 words per second
peak memory: 0.3 GB (VmHWM)
of which file-backed: under 0.1 GB (RssFile, at the highest sample)
Every figure matches what the simulated model is known to do. The first word came 1.25 s after the start, plus the few milliseconds it takes to pass text through a pipe, which rounds to 1.3 s. The pace is 10 words per second. The peak of about 0.3 GB is the 250 MB block plus the memory Node.js itself uses, and the small file-backed part is the Node.js program and its libraries, mapped from disk. If your computer is busy, a time can come out 0.1 s higher; the automated check that reruns this page allows each command three attempts for that reason.
Now the same simulated model as a server:
Run
node measure-model.mjs measure --server -- node measure-model.mjs simulate --serve {port}
Expected output (simulated model)
measured: node measure-model.mjs simulate --serve {port}
server ready after: 1.3 s (start-up and loading)
memory when ready: 0.3 GB (VmRSS)
time to first token: 0.3 s (from sending the request)
generated: 49 tokens, as counted by the server; text begins: "This text comes from the simulated model in ..."
generation rate: 10 tokens per second
the server's own figure: 10 tokens per second (timings.predicted_per_second)
peak memory: 0.3 GB (VmHWM)
of which file-backed: under 0.1 GB (RssFile, at the highest sample)
Loading (1.3 s) and answering (0.3 s to the first token) are now separate figures. The last rate line is the server's own measurement, which llama-server sends in a timings object; the simulated server imitates it. Two independent readings that agree are a good sign that neither is distorted.
With a real model
These steps use llama.cpp and Qwen3.5-0.8B, a small open-weight model published under the Apache 2.0 licence, in the file Qwen3.5-0.8B-Q4_0.gguf (563 MB). Backprop Bulletin did not run these steps for this guide: no real model was downloaded or measured. The file names, sizes and SHA-256 values below are the ones GitHub and Hugging Face list for these files, copied on 18 November 2026. The commands are for Linux on a 64-bit Intel or AMD processor; if uname -m prints aarch64, use the ubuntu-arm64 archive from the same release page and check its own SHA-256 there.
- Download llama.cpp. The notes of llama.cpp release v1.0.0, published on 13 November 2026, point to build b12359 for its programs. This archive is the Linux build that runs on the processor alone:
curl -LO https://github.com/ggml-org/llama.cpp/releases/download/b12359/llama-b12359-bin-ubuntu-x64.tar.gz - Check it against the SHA-256 that GitHub lists beside the file on the release page. The command should print
llama-b12359-bin-ubuntu-x64.tar.gz: OK; if it prints anything else, delete the file and do not run it:echo "0bc1f091e8916102b6d8f2cf944233a620e90a0f856c72d0ce41150c65c2e72e llama-b12359-bin-ubuntu-x64.tar.gz" | sha256sum -c - Unpack it. The release's build script packs
llama-server,llama-completionand the other programs into one folder,llama-b12359; if yours unpacks differently, adjust the paths below:tar -xzf llama-b12359-bin-ubuntu-x64.tar.gz ./llama-b12359/llama-server --version - Download the model from the ggml-org/Qwen3.5-0.8B-GGUF repository on Hugging Face, pinned to the revision checked for this guide (the file is 563,036,064 bytes):
curl -L -o Qwen3.5-0.8B-Q4_0.gguf https://huggingface.co/ggml-org/Qwen3.5-0.8B-GGUF/resolve/004fd086eccea9f7cf867aa07ba328773beef81d/Qwen3.5-0.8B-Q4_0.gguf - Check it against the SHA-256 that Hugging Face lists on the file's page. It should print
Qwen3.5-0.8B-Q4_0.gguf: OK:echo "57d1997790d1744fba5b40a7317df71ea5e2acee28c47e78f0cce39c0703f8cf Qwen3.5-0.8B-Q4_0.gguf" | sha256sum -c - Measure the server.
-c 4096sets a context of 4,096 tokens, plenty for one short prompt. Without it, llama.cpp uses the size the model declares, which for this model is 262,144 tokens.--no-uiturns off the built-in chat app, and--offlinestops the server from using the network:node measure-model.mjs measure --server -- ./llama-b12359/llama-server -m Qwen3.5-0.8B-Q4_0.gguf -c 4096 --port {port} --no-ui --offline
Shape of the output (not a measurement: your figures replace the words in angle brackets)
measured: ./llama-b12359/llama-server -m Qwen3.5-0.8B-Q4_0.gguf -c 4096 --port {port} --no-ui --offline
server ready after: <seconds> s (start-up and loading)
memory when ready: <size> GB (VmRSS)
time to first token: <seconds> s (from sending the request)
generated: <count> tokens, as counted by the server; text begins: "<the first words of the answer> ..."
generation rate: <rate> tokens per second
the server's own figure: <rate> tokens per second (timings.predicted_per_second)
peak memory: <size> GB (VmHWM)
of which file-backed: <size> GB (RssFile, at the highest sample)
To measure a single run from the command line instead, use output mode with llama-completion. Here -st runs one turn of conversation and exits, -n 128 limits the answer to 128 tokens, and --no-display-prompt keeps your prompt out of the output, so that the first output should be generated text:
node measure-model.mjs measure -- ./llama-b12359/llama-completion -m Qwen3.5-0.8B-Q4_0.gguf -c 4096 -n 128 -st --no-display-prompt --simple-io --offline -p "Explain in three sentences what a language model is."
Check the output begins line: it shows exactly what the meter timed. If it starts with your prompt or a banner rather than the answer, time to first output measured that instead.
Reading the figures
No figures for a real model appear on this page, because Backprop Bulletin did not measure one. This is what each line means, and what to look for in yours:
- server ready after: starting the program and loading the model. Run the measurement twice. If the second run is ready much sooner, the first was probably waiting for the disk.
- memory when ready: what the server holds once loaded, before any request.
- time to first token: from sending the request to the first piece of the answer. The server processes the whole prompt before it generates anything (its
timingsreport the two phases separately, asprompt_msandpredicted_ms), so this grows with the length of the prompt. For a short prompt it should be small next to the time the whole answer takes. - generated: how many tokens the answer had, as the server counted them. If it says "pieces of text" instead, the server did not send a count, and the rate counts pieces.
- generation rate and the server's own figure: tokens per second after the first. The two should be close. If several runs give similar rates, the figure is stable enough to plan with; if they swing widely, something else on the computer is competing for it.
- peak memory: the most resident memory at any moment. It should stay well below the memory your computer has available (
free -hshows it), leaving room for everything else you run. - of which file-backed: llama.cpp's default load mode memory-maps the model file where it can, and the parts of the file in memory are counted here. To see the difference, run the measurement again with
--load-mode noneadded to the server's options, and compare the two memory lines. Try a larger-cas well, and compare peak memory again.
Where the measurement stops being reliable
A program that holds its output in a buffer
The meter can only time what reaches it. Many programs write their output to a buffer in memory and pass it on in large blocks. The POSIX standard for C's input and output streams says standard output is "fully buffered" when it is not connected to an interactive device, which is exactly the situation when the meter reads it through a pipe. The simulated model can behave like such a program:
if (!buffered || pending.length >= 4096) {
Measure it with --buffered. It generates its words at exactly the same pace as before, but keeps them in a 4 KB buffer that never fills:
Run
node measure-model.mjs measure -- node measure-model.mjs simulate --buffered
Expected output (simulated model)
measured: node measure-model.mjs simulate --buffered
exit status: 0
time to first output: 6.1 s (includes start-up and loading)
output: 49 words; output begins: "This text comes from the simulated model in ..."
output rate: not measured: the output arrived in 1 read within 0.0 s.
The program may be holding its output in a buffer; see the guide.
peak memory: 0.3 GB (VmHWM)
of which file-backed: under 0.1 GB (RssFile, at the highest sample)
The model was just as fast as before, but the meter now reports a first output 4.8 s later and cannot report a rate. It refuses to guess a rate, but it cannot correct the time to first output: from outside, a slow model and a buffered one look the same. If this happens with your program, make it write as it goes. Python has the -u option for this; for a program that uses the C library's default buffering, stdbuf -oL before the command makes output line-buffered, though it has no effect on a program that sets its own buffering. Server mode avoids the problem, because streaming is part of the request.
A script that starts the model
The meter measures the memory of the process it starts. If that process is a script that starts the model, it measures the script:
Run
node measure-model.mjs measure -- sh -c 'node measure-model.mjs simulate; true'
Expected output (simulated model)
measured: sh -c 'node measure-model.mjs simulate; true'
exit status: 0
time to first output: 1.3 s (includes start-up and loading)
output: 49 words; output begins: "This text comes from the simulated model in ..."
output rate: 10 words per second
peak memory: under 0.1 GB (VmHWM)
of which file-backed: under 0.1 GB (RssFile, at the highest sample)
warning: the measured process started 1 other process; their memory is not included above.
Measure the model program itself, not a script or wrapper that starts it.
The timing is still right, because the model writes to the same output. The memory is the shell's, not the model's 0.3 GB. The ; true keeps the shell running after the model starts; without it, a shell may hand its process over to the model, and the problem would not show. Point the meter at the model program itself.
Clean up
The meter writes no files, and it stops every server it starts. If you followed the steps with a real model, delete the llama.cpp folder, its archive and the model file, then the meter itself:
rm -rf llama-b12359 llama-b12359-bin-ubuntu-x64.tar.gz Qwen3.5-0.8B-Q4_0.gguf measure-model.mjs
If you stopped a measurement with Ctrl+C while a server was running, check that no llama-server is left behind with pgrep -a llama-server, and stop any that is with kill and its process number.
What this does not measure
- Quality. A fast answer can be a wrong one. Use the meter alongside a check of the answers themselves, such as our guide to comparing two models on the same workload.
- One run is one sample. Measure several times, and with prompts like the ones you will really use: a longer prompt takes longer before the first token.
- The memory figures are approximate. The Linux manual says the figures in
/proc/<pid>/statusare inaccurate because of a scalability optimisation in the kernel, and points to/proc/<pid>/smaps_rollupfor accurate figures, which is much slower to read. - Memory on a graphics card is not included. The meter reads only the process's resident memory as Linux reports it.
- A peak in the last moments can be missed. The kernel's high-water mark covers the whole run, but the meter reads it every 0.1 s, so memory taken just before the program exits may not be seen.
- Words are not tokens. In output mode the rate is in words. Models report tokens, and a word can be one token or several, so the two rates are not directly comparable.
- It is a teaching example. It measures one program at a time, on Linux only, and has no tests of its own beyond the commands on this page.
Sources
Technical statements on this page were checked against these primary sources on 18 November 2026:
- Linux manual: proc_pid_status(5):
VmHWMis the peak resident set size,VmRSSis the sum ofRssAnon,RssFileandRssShmem, andRssFileis the size of resident file mappings. - Linux manual: proc_pid_statm(5): some of these values are inaccurate because of a kernel-internal scalability optimisation;
smapsandsmaps_rollupare accurate but much slower. - Linux manual: proc_pid_stat(5): field 4,
ppid, is the process number of the parent. - Node.js: performance.now() and performance.timeOrigin: the high-resolution clock the meter and the simulated model use.
- POSIX.1-2024: stdin, stdout, stderr: standard output is fully buffered if and only if it is not associated with an interactive device.
- Python: the -u option: forces the standard output and error streams to be unbuffered.
- Linux manual: stdbuf(1):
-oLmakes standard output line-buffered, unless the command adjusts its own buffering. - llama.cpp: llama-server documentation:
GET /healthanswers 503 while loading and 200 when ready; the chat completions endpoint, itsusageandtimings;-c,--load-mode,--port,--no-uiand--offline. - llama.cpp: llama-completion documentation:
-st,-n,--no-display-promptand--simple-io. - llama.cpp release v1.0.0, whose notes name nightly build b12359, and build b12359, which lists
llama-b12359-bin-ubuntu-x64.tar.gzwith its SHA-256. - llama.cpp: the release build script at b12359: the Ubuntu archives pack the built programs into one folder named after the build.
- GitHub changelog: releases now expose digests for release assets: GitHub computes and shows a SHA-256 for every uploaded release file.
- Hugging Face: ggml-org/Qwen3.5-0.8B-GGUF: the GGUF files, their sizes and SHA-256 values.
- Hugging Face: Qwen/Qwen3.5-0.8B model card: the Apache 2.0 licence and the context length of 262,144 tokens.
- OpenAI API reference: create chat completion:
stream_options.include_usageadds a final chunk with the token usage for the whole request.