Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows system time with millisecond precision

Related to my previous question, but with C#, I need the precise system time including milliseconds.

C# time function has accuracy up to 10 to 15 milliseconds, but not exactly 1 millisecond.

The same is the case with Queue performance counter. Is there any other way to get accuracy up to exact millisecond?

like image 798
Badr Avatar asked Jun 29 '10 13:06

Badr


People also ask

How accurate is Windows time?

Under the right operating conditions, systems running Windows 10 or Windows Server 2016 and newer releases can deliver 1 second, 50 ms (milliseconds), or 1 ms accuracy. The resulting time accuracy in your topology is highly dependent on using an accurate, stable root (stratum 1) time source.


1 Answers

Windows does not want to waste electricity by updating the system clock 1000 times per second, so the default is to only update it 60-100 times per second. If you set the multimedia timer to 1ms, you can get 1ms resolution from the clock, but that's not recommended.

To elaborate more on the electricity savings, what happens when the CPU is idle for a period of time is that it can go into a very-low-power state. Whenever it gets interrupted (e.g. to increment the clock ticks) it has to leave its very-low-power state and use lots of electricity to power the whole CPU to service that interrupt. In other words, the additional power isn't in incrementing the clock ticks, it's in keeping the CPU awake to do it.

Since my laptop uses 10W at idle when the clock frequency is 60Hz and 11W when it's 1000Hz, and I get 300 minutes of battery life, that slower clock is giving me almost 30 extra minutes of battery life!

like image 124
Gabe Avatar answered Sep 19 '22 00:09

Gabe