“It feels slow” is a reasonable reason to investigate, but it does not tell you what to change. Waiting before the first visible text can come from loading the model or evaluating a long prompt. Slow output after the first text is a different problem. A useful measurement separates those stages before you change hardware, model, context, or prompt.
Ollama’s API returns usage fields such as load_duration, prompt_eval_duration, eval_duration, and token counts. Its timing values are in nanoseconds. For a streaming call, usage appears in the final chunk. The snippet below measures wall-clock time to first non-empty text as well, so you can compare the user-visible wait with the server’s breakdown.
A minimal streaming harness
Use Node.js 20 or newer, a running local Ollama server, and an already-installed model. Set OLLAMA_MODEL to that model. Run the script once after restarting Ollama, then several times without restarting. Label the first observation “after restart” and the others “warm”; restarting does not clear operating-system caches.
// save as measure.mjs const model = process.env.OLLAMA_MODEL; if (!model) throw new Error('Set OLLAMA_MODEL to a model already available in Ollama'); const started = process.hrtime.bigint(); const response = await fetch('http://localhost:11434/api/generate', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ model, prompt: 'Explain why measuring first-token latency differs from measuring tokens per second.', stream: true, options: { num_predict: 120 }, }), signal: AbortSignal.timeout(180_000), }); if (!response.ok || !response.body) throw new Error(`Ollama HTTP ${response.status}`); const reader = response.body.getReader(); const decoder = new TextDecoder(); let pending = ''; let firstTextMs; let final; async function consumeRecord(line) { if (!line.trim()) return; const chunk = JSON.parse(line); if (chunk.error) throw new Error(`Ollama stream error: ${chunk.error}`); if (firstTextMs === undefined && chunk.response) { firstTextMs = Number(process.hrtime.bigint() - started) / 1e6; } if (chunk.done) final = chunk; } let parsedSuccessfully = false; try { while (true) { const { value, done } = await reader.read(); pending += decoder.decode(value ?? new Uint8Array(), { stream: !done }); const lines = pending.split('\n'); pending = lines.pop() ?? ''; for (const line of lines) await consumeRecord(line); if (done) break; } if (pending.trim()) await consumeRecord(pending); if (!final) throw new Error('Stream ended without a final usage chunk'); parsedSuccessfully = true; } finally { if (!parsedSuccessfully) await reader.cancel().catch(() => {}); reader.releaseLock(); } const nsToMs = (ns) => Number(ns ?? 0) / 1e6; const tokensPerSecond = final.eval_duration > 0 ? final.eval_count / (final.eval_duration / 1e9) : null; console.log(JSON.stringify({ model: final.model, wallMs: Number(process.hrtime.bigint() - started) / 1e6, firstTextMs, loadMs: nsToMs(final.load_duration), promptTokens: final.prompt_eval_count, promptEvalMs: nsToMs(final.prompt_eval_duration), outputTokens: final.eval_count, generationMs: nsToMs(final.eval_duration), outputTokensPerSecond: tokensPerSecond, }, null, 2)); The tokens-per-second figure uses Ollama’s output-token count divided by generation duration. Wall time also includes loading, prompt evaluation, and transport. firstTextMs measures the client's wait for the first non-empty response chunk. It excludes the separate thinking field and measures answer-text arrival at the client, which can be later than token generation inside the server.
Run a fair comparison
Use the same prompt, output limit, model tag, context setting, and machine state when comparing configurations. Capture multiple warm runs and report the range or median, not only the fastest result. Label the first run separately. If you change prompt length, record prompt tokens too: prompt evaluation is part of the initial wait and can dominate a long-context task.
Read the timings together. A long wait for first text accompanied by a high load duration points toward model loading. High prompt-evaluation time gives you a reason to try a shorter input. If answer text starts quickly but trickles out, compare generation rates under the same output limit. Each pattern suggests a different experiment before a hardware purchase.
Keep wallMs alongside server durations to capture the full client wait. Note concurrent workloads, GPU placement from ollama ps, and whether the first run loaded the model. Repeat the comparison with your application's prompt lengths and target concurrency before using it to choose hardware.
The Ollama usage reference defines the timing fields and nanosecond units; the generate API documents streaming responses.