---
title: "Measure TTFT and inter-token gaps"
lesson_id: "03"
---

# Measure TTFT and inter-token gaps

- **Lesson ID:** 03
- **Goal:** Measure TTFT and inter-token latency around the stream with a monotonic clock.
- **Human lesson:** [03-measure-ttft-and-gaps.html](03-measure-ttft-and-gaps.html)

## Prerequisites

- Lesson 02, or a working streamResponse loop.

## Inputs, outputs, and artifacts

- **Inputs:** A live stream of partial snapshots.
- **Outputs:** TTFT, mean inter-token gap, yield count, and total time.
- **Artifacts:** A metrics sketch and progressive `.flow` diagrams.

## Agent build steps

1. Start a ContinuousClock before streamResponse.
2. Mark the first yield as TTFT.
3. Derive mean inter-token gap from later yields.
4. Warn that a yield is a snapshot, not always one token.
5. Link the eval harness course.

## Constraints

Keep the language simple, friendly, and literal. iOS 27 and macOS 27 only. No quizzes, Mermaid, or em dashes. Do not invent API names. Mark sketches as sketches and tell the reader to confirm them in the Xcode 27 SDK.

## Key concepts

- Instruments reports TTFT, tokens per second, and total latency. Mirror those in debug logs.
- Use `ContinuousClock`, not wall-clock `Date`.
- A yield is aggregated text, not always one token.
- Log TTFT, inter-token mean, yield count, and total time with model, profile, and prompt version.

## Takeaways

- Log four numbers on every debug session.
- Say in the log that yield gaps are snapshot gaps.
- A faster TTFT from dropping required facts is not a win.

## Acceptance checks

- TTFT and inter-token mean are both defined.
- ContinuousClock is used, not Date.
- Yield versus token is stated.
- Sibling links, progressive `.flow` diagrams, and an Agent brief link are present.
- [ ] Proceed to [lesson 04 brief](04-on-device-vs-pcc.llms.md).
