calculate average latency