complete code about lantency calculate.