Timers to measure latency

后端 未结 3 1866
-上瘾入骨i
-上瘾入骨i 2021-01-06 04:03

When measuring network latency (time ack received - time msg sent) in any protocol over TCP, what timer would you recommend to use and why? What resolution does it have? Wha

3条回答
  •  一个人的身影
    2021-01-06 04:29

    There is really no substitute for the rdtsc instruction. You cannot be sure of what resolution the QueryPerformanceCounter will support. Some have a very large granularity (low increment rate/frequency), some return nothing at all.

    Instead, I recommend you use the rdtsc instruction. It does not require any OS implementation and returns the number of CPU internal clock cycles that have elapsed since the computer/processor/core was powered up. For a 3 GHz processor that's 3 billion increments per second - it doesn't get more precise than that, now does it? This instruction is available for x86-32 and -64 beginning with the Pentium or Pentium MMX. It should therefore be accessible from x86 Linuxes as well.

    There are plenty of posts about it here on stackoverflow.com. I've written a few myself ...

提交回复
热议问题