Classify a latency measurement
Monitoring dashboards colour-code every request by how long it took. Bucket the latency into a human-readable band.
- Under 250 ms is "fast".
- Under 1000 ms is "normal".
- Under 3000 ms is "slow".
- Anything at or above 3000 ms is "timeout".
latency_band(latency_ms: int) → string
Where you start
def latency_band(latency_ms: int) -> str:
Worked examples
| Call | Result |
|---|---|
latency_band(0) | "fast" |
latency_band(100) | "fast" |
latency_band(250) | "normal" |
latency_band(999) | "normal" |
Hint
Check the thresholds from smallest to largest.
Reference solution in Python
def latency_band(latency_ms: int) -> str:
if latency_ms < 250:
return "fast"
if latency_ms < 1000:
return "normal"
if latency_ms < 3000:
return "slow"
return "timeout"