Reputation: 198188
From this question System.currentTimeMillis() is not accurate on windows XP? I know that on windows XP, the time interval is 15ms or 16ms with Java.
But is it only Java's problem? If I use C/C++/Python, can I get a more accurate time interval on windows XP?
Upvotes: 1
Views: 470
Reputation: 533442
You can base the time on nanoTime instead of millis. The problem you have with millis is that the clock can drift by as much as 10 ms in an hour on some systems and windows only does NTP synchronisation once a week.
Upvotes: 1
Reputation: 1
It is probably an operating system issue, so would be the same in any language interfacing the same way to the operating system kernel.
I don't know Windows (never used it), but on Linux systems, it depends upon the kernel and configuration parameters like CONFIG_HIGH_RES_TIMERS
and others.
Rumors say that Windows is much more poor on these issues than Linux.
Maybe you could try GNU/Linux? It is always an interesting experience, and most importantly, it is free software and this means you can study it and improve it. Last time I checked, Windows does not have this property (and that is why I don't use it).
Upvotes: 2
Reputation: 70369
This doesn't have much to do with language!
It has to do how the function you use is implemented... which again has to do with the APIs available in the OS (different API function can have different accuracy) you use AND with the hardware you are running on (different CPU/chipset can expose different ways and different accuracy)...
Upvotes: 2
Reputation: 108790
Most time functions suffer from this issue, regardless of language. This includes GetTickCount
and functions that give you the current time.
It's possible to decrease that interval to 1ms using timeBeginPeriod
, but this has a global effect and can increase power consumption. So it should be avoided where possible.
There is the QueryPerformanceCounter
API which supports high precision timings, but it suffers from its own problems, such as desyncronizing between multiple cores on some (buggy) hardware.
Upvotes: 2