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".
LatencyBand(latencyMs: int) → string
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public string LatencyBand(int latencyMs) {
}
Worked examples
| Call | Result |
|---|---|
LatencyBand(0) | "fast" |
LatencyBand(100) | "fast" |
LatencyBand(250) | "normal" |
LatencyBand(999) | "normal" |
Hint
Check the thresholds from smallest to largest.
Reference solution in C#
public string LatencyBand(int latencyMs) {
if (latencyMs < 250) return "fast";
if (latencyMs < 1000) return "normal";
if (latencyMs < 3000) return "slow";
return "timeout";
}