Added latency measurement code