Re: new Date(), System.currentTimeMillis() and system clock accuracy



On Jul 4, 3:05 am, Numeron <irunsofastineedafinonmyh...@xxxxxxxxxxx>
wrote:
Hi,
Im having a problem getting a higher resolution than 10ms on my system
clock (on XP) using both the getTime() method in Date and the
currentTimeMillis() method in System to measure the time elapsed
between two points in my code. I wrote this small peice to test this
resolution:

long milliseconds;
for(int i = 0; i != 50; i++){
  long time1 = System.currentTimeMillis();
  long time2;
  milliseconds = 0;
  while(milliseconds < 1){
    time2 = System.currentTimeMillis();
    milliseconds = time2 - time1;
  }
  System.out.println("currentTimeMillis(): " + milliseconds + "ms");}

for(int i = 0; i != 50; i++){
  Date date1 = new Date();
  Date date2;
  milliseconds = 0;
  while(milliseconds < 1){
    date2 = new Date();
    milliseconds = date2.getTime() - date1.getTime();
  }
  System.out.println("new Date(): " + milliseconds + "ms");

}

Each method assumedly gets its time from the same place since they
return very much the same values (lots of 10ms and the occasional
20ms). Is there some way to update the system clock before checking
it? I really need a granularity of 1ms for my program to work.

-Numeron

Looks like it only handles 10ms on Windows Xp:

http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=eb9d3ee134a0ad25c67faba39ef5?bug_id=4313758

"For example, many operating systems measure time in units of tens of
milliseconds. "
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()

Jon.
.



Relevant Pages

  • Re: Time Dilation reduces the Speed of moving Objects
    ... have to place that new speed into the time dilation formula. ...    The result is the spaceship goes at 0 km/s. ... One justification is that recalculating the rate of ticks in a clock ... electrons, with no neutrons. ...
    (sci.physics.relativity)
  • Re: Time Dilation reduces the Speed of moving Objects
    ... have to place that new speed into the time dilation formula. ...    The result is the spaceship goes at 0 km/s. ... One justification is that recalculating the rate of ticks in a clock ... electrons, with no neutrons. ...
    (sci.physics.relativity)
  • Re: Time Dilation reduces the Speed of moving Objects
    ... have to place that new speed into the time dilation formula. ...    The result is the spaceship goes at 0 km/s. ... One justification is that recalculating the rate of ticks in a clock ... electrons, with no neutrons. ...
    (sci.physics.relativity)
  • Re: Time Dilation reduces the Speed of moving Objects
    ... have to place that new speed into the time dilation formula. ...    The result is the spaceship goes at 0 km/s. ... One justification is that recalculating the rate of ticks in a clock ... electrons, with no neutrons. ...
    (sci.physics.relativity)
  • Re: time dilation
    ...      Not true. ... clock in S ticks, then the equation for t' shows that the Lorentz ... from the ceiling of the train, it does not tick after it hits the ... acceleration is the same in both frame? ...
    (sci.physics.relativity)