Skip to content

bench: measure context tokens per request over a scripted session - #430

Merged
mrnasil merged 1 commit into
mainfrom
bench/token-harness
Nov 7, 2026
Merged

mrnasil merged 1 commit into
mainfrom
bench/token-harness

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 7, 2026

Copy link
Copy Markdown
Member

Makes the token measurements behind #418–#428 repeatable, so the savings can be re-checked after any change to prompts, tool output or context handling.

scripts/bench_tokens.py

  • Runs a fixed two-turn session in --plain mode against the repository:
    • Turn 1: a large read (outline), a small read, grep, a 60-line write, and a failing test that prints 4,000 lines.
    • Turn 2: a read and a grep.
  • A local OpenAI-compatible mock plays the model and records every request. It runs under a throwaway WHYCODES_HOME, so the real account is never touched and nothing is billed. The test file written during the run is removed afterwards.
  • For each request it reports:
    • the total input;
    • the prefix that repeats the previous request byte for byte, which is what a prompt cache can serve;
    • uncached, the remainder.
  • Counts use tiktoken o200k when installed and chars/4 otherwise; the output states which. --compare runs a second binary side by side, and --json records the result.

docs/benchmarks.md

  • New "Context tokens per session" section: a per-request table for v0.6.33 against v0.6.34, and which PR each saving comes from.
    • Total input: 305,828 → 187,053 (−39%)
    • Uncached: 152,356 → 49,536 (−67%)
  • It also covers the one remaining cache miss (old results shrunk in place) and why it stays. The miss costs about 17.8k tokens processed once and saves about 15k on every later request. With prompt-cache pricing it pays for itself in roughly a dozen requests, and from the next request without a cache.
  • "Running them" now lists the command.

Checks

  • I ran the script on Windows with release binaries; it reproduces the hand measurements exactly.
  • check_tracked_secrets is ok (the mock key sk-mock is not flagged).

🤖 Generated with Claude Code

`scripts/bench_tokens.py` runs a fixed two-turn session (large and small
read, grep, a 60-line write, a failing 4,000-line test, then a second
turn) against the repository in `--plain` mode. A local OpenAI-compatible
mock plays the model and records every request, under a throwaway
`WHYCODES_HOME`. For each request it counts the input (tiktoken o200k when
installed, chars/4 otherwise) and the prefix repeated byte for byte from
the previous request, i.e. what a prompt cache can serve. `--compare`
runs a second binary side by side.

docs/benchmarks.md records v0.6.33 against v0.6.34: total input
305,828 -> 187,053 (-39%), uncached 152,356 -> 49,536 (-67%), with the
source of each saving, and why the one remaining cache miss (shrinking
old results in place) is kept: it pays for itself in about a dozen
requests with a prompt cache and immediately without one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil merged commit daa1840 into main Nov 7, 2026
7 checks passed
@mrnasil
mrnasil deleted the bench/token-harness branch November 7, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant