add R code for latency measurement