1

I want to compute some latencies in my server-client application. I was thinking about measuring the time when I send a package from client A, then the time when it arrives on the server, and a third time when it arrives the client B. I was thinking about using DateTime.UtcNow, but then realized that it takes the system time, which will surely differ on all three machines. Since my measurement will be couple thousand nanoseconds only, surely less than 10ms, since all machines are in a network.

Is there a way to have exact time on all three machines? Possibly without using a external server, where I have to use HTTP requests.

CuriousFella
  • 23
  • 1
  • 3
  • 2
    Note that [`DateTime.Now`](https://msdn.microsoft.com/en-us/library/system.datetime.now(v=vs.110).aspx) only has a resolution of 15ms: "The resolution of this property depends on the system timer, which is approximately 15 milliseconds on Windows systems.As a result, repeated calls to the Now property in a short time interval, such as in a loop, may return the same value.". So even if you synchronized to 1ms, using datetime.now will shift up to ~15ms anyway. Some more reading [here](http://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution). – Quantic Nov 08 '16 at 22:48
  • @Quantic Thank you! That was very helpful. Using the `StopWatch` class is more useful in this case! I guess I can only reliably compute the time it took from `client A` to `server` back to `client A`. A good quote from the blog post, you posted: "“how much time has elapsed from start to finish?” is a completely different question than “what time is it right now?”" – CuriousFella Nov 08 '16 at 23:08

0 Answers0