Latency versus throughput
Quick answer
Latency is the elapsed time for one operation; throughput counts completed work per unit of wall-clock time. A faster batch can improve rows per second while increasing the time a single request waits. Examples use Python and NumPy 2.3.5. Timing examples use fixed synthetic values; actual benchmark timings are in the milestone. ByteMind execution is unverified.
Nearest-rank percentile
import mathx=sorted([9,1,4,2,7])print(x[math.ceil(.5*len(x))-1],x[math.ceil(.95*len(x))-1])Expected output (locally tested): 4 9. Sorting and a specified rank make the result reproducible.
How it works
Choose the measurement boundary before collecting samples. Client latency includes queue wait, preprocessing, computation and response overhead; a local kernel timer measures only computation plus whatever is inside the timed call. Use a monotonic high-resolution clock such as time.perf_counter_ns, warm up the exact operation, and measure a fixed number of calls. Report units, batch size, sample count, concurrency and hardware context. The nearest-rank percentile sorts n measurements and selects index ceil(p*n)-1 for p in (0,1]. For 20 measurements, p95 is the 19th sorted value. This definition differs from interpolated percentiles. Throughput is total completed rows divided by total elapsed seconds, not the reciprocal of p95 latency. Measure error and rejected work separately; never omit slow or failed requests from a service report without describing the policy.
Completed rows per second
rows=8*20elapsed_seconds=2print(rows/elapsed_seconds)Expected output (locally tested): 80.0. Throughput counts rows rather than calls.
Common mistakes
Do not compare single-row latency with batch throughput as if they had the same units. Do not confuse p95 with the worst case, or report p99 as a reliable tail estimate from ten samples.
Practice and next steps
Compute p50 and p95 from the same ten synthetic durations, then compare single-row and batched throughput using a fixed total work count.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Latency versus throughput — knowledge check
Apply latency versus throughput to small examples and debugging scenarios.
What does throughput count?
What does nearest-rank p95 select from 20 sorted samples?
Which clock is suitable for elapsed durations?
Why warm up?
What does a local kernel timer omit?