Benchmarking Gemini 3.8 Flash Latency and Cost Across Agent Workloads
Build a benchmark harness that measures TTFT, throughput, tool overhead, and cost per turn for Flash-class workloads, read percentiles honestly, and turn the results into routing and budget decisions.
Published on • November 27, 2026
AI Assistant

“Flash is fast and cheap” is a slogan, not an engineering number. What you actually need to know is whether your agent’s turns fit inside your budget — p95 latency under two seconds, cost per resolved conversation under a cent — and which part of the turn is spending the time and the tokens.
This article is about building that measurement: a repeatable harness for ADK workloads, the metrics worth collecting, and how to convert results into routing decisions instead of a spreadsheet nobody reads.
Define the workload before you define the benchmark
A benchmark without a workload definition is a speed test. Capture three things first:
- Turn shapes. A triage turn (short prompt, 1–2 tools) and a research turn (long prompt, 10 tools, grounding) are different products. Bucket them.
- Context sizes. Realistic system instruction length, history depth, and RAG payload — not a hello-world prompt.
- Success criteria. Correct tool selection, valid arguments, acceptable answer. Latency of a wrong answer is meaningless.
A practical dataset is 50–200 labelled turns per bucket, replayed from production traffic with the sensitive bits scrubbed.
The metrics that matter
| Metric | Definition | Why it matters |
|---|---|---|
| TTFT | Request → first token | Perceived responsiveness (see TTFT optimization) |
| Inter-token latency / throughput | Sustained tokens/sec | Rendering and read speed |
| Tool overhead | Time inside tool execution | Often dominates multi-step turns |
| Turn count | Model calls per resolved turn | Multiplies everything above |
| End-to-end latency | Request → final answer | The SLA number |
| Cost per turn | Input + cached + output tokens × prices | The budget number |
| Quality | Tool-match / judge score / task success | The gate on all of the above |
The single most under-measured item is turn count. A model that needs three round trips to reach an answer loses to a slower model that gets it in one — and each extra turn pays full input cost again for the accumulated history.
The harness
import asyncio, time, statistics
async def bench_turn(runner, session_id, user_id, message, expected=None):
t0 = time.perf_counter()
first_token = None
text = ''
tool_ms = 0.0
async for event in runner.run_async(
session_id=session_id, user_id=user_id, new_message=message
):
now = time.perf_counter()
if event.content and event.content.parts:
chunk = ''.join(p.text or '' for p in event.content.parts)
if chunk and first_token is None:
first_token = now
text += chunk
if event.get('event_id') and getattr(event, 'usage_metadata', None):
last_usage = event.usage_metadata # keep the latest usage snapshot
end = time.perf_counter()
u = last_usage
return {
'ttft_s': None if first_token is None else round(first_token - t0, 3),
'total_s': round(end - t0, 3),
'prompt_tokens': getattr(u, 'prompt_token_count', 0),
'output_tokens': getattr(u, 'candidates_token_count', 0),
'cached_tokens': getattr(u, 'cached_content_token_count', 0) or 0,
'quality': grade(text, expected),
}
def percentile(xs, p):
xs = sorted(xs)
return xs[min(len(xs) - 1, int(len(xs) * p))] if xs else None
Cost comes from the usage metadata, not from tokenizing yourself:
def turn_cost(r, price_in, price_out, price_cached):
return (
r['prompt_tokens'] * price_in
+ r['cached_tokens'] * price_cached
+ r['output_tokens'] * price_out
) / 1_000_000
Discipline that keeps the numbers real:
- Warm up first. Discard the first few runs; they measure cold connections.
- Pin concurrency. Run the same concurrency you’ll have in production; per-request latency degrades under load.
- Report p50 and p95, never just the mean. Latency distributions have long tails.
- Repeat across days. Endpoint load varies; a single afternoon’s numbers are a sample, not a fact.
- Record the exact model ID and config (temperature, thinking budget, tool count) with every run.
Reading the results: a worked comparison
Suppose a customer-support triage workload, 100 turns, Flash-tier only:
| Metric | Turn A: triage, 2 tools | Turn B: research, 12 tools + grounding |
|---|---|---|
| p50 TTFT | 0.4 s | 0.7 s |
| p95 end-to-end | 2.1 s | 9.8 s |
| Avg turns per resolution | 1.4 | 3.9 |
| Avg input tokens | 4.1k | 18.6k (cached 62%) |
| Avg output tokens | 140 | 520 |
| Cost per turn | low | 6× Turn A |
| Task success | 96% | 88% |
Decisions that fall out of this table:
- Turn A is fine — ship it, and stop worrying about it. Optimization effort there is wasted.
- Turn B’s tail is the problem, and the driver is turn count × accumulated history, not raw model speed. Trim history between stages, or restructure so research doesn’t re-send 18k tokens per round trip.
- Cache hit rate of 62% is an opportunity — a stable prefix (system instruction + tool declarations) that isn’t changing shape would push this higher; see cache-aware prompting.
- 88% success with 3.9 turns suggests wasted work: measure how often the model re-reads the same document twice.
From benchmark to routing
The benchmark earns its keep when it changes configuration:
- Bucket by measured cost and depth. Turns that succeed in one short call on Flash stay on Flash; turns that need long-horizon reasoning get the deeper tier — precisely what model routing formalizes.
- Set budgets from percentiles. p95 latency becomes your client timeout; p95 cost becomes the per-conversation cap.
- Guard quality with a gate. Any prompt/model change runs the same harness; a quality drop beyond a threshold blocks the deploy.
- Track over time. A rising cost-per-turn at constant traffic is a regression signal — usually prompt bloat or an agent that has started over-calling tools.
Takeaways
- Define workloads (turn shapes, context sizes, success criteria) before measuring anything.
- Measure TTFT, throughput, tool overhead, turn count, cost, and quality together — latency alone lies.
- Use usage metadata for token counts, warm up, fix concurrency, and report p50/p95 across days.
- The output is configuration: routing buckets, timeouts, budgets, and a regression gate for changes.
- Watch cost-per-turn over time at constant traffic; growth there is silent bloat.