Here's another measurement.. how often DateAndTime now drifts from system time.

(put this method on DateAndTime class  side)

calculateDrift
        |  durationSinceEpoch systemSeconds milSince secDrifted
systemSecondsSinceMidnight |

        "those two must be close to minimize time distance between measurement" 
        systemSeconds := Time primSecondsClock.
"       uncomment to see that drift calculation is correct      
        
        (Delay forSeconds: 5) wait.
"       
        milSince := self milliSecondsSinceMidnight.

        secDrifted := milSince // 1000.
                
        durationSinceEpoch := Duration
                days: SqueakEpoch
                hours: 0
                minutes: 0
                seconds: systemSeconds.
                
        systemSecondsSinceMidnight := durationSinceEpoch -
(durationSinceEpoch days days).
        
         ^(Duration seconds: secDrifted) - systemSecondsSinceMidnight

============
Now the experiment, we run this stuff in a tight loop and see
how many times the drift (expressed in seconds is non-zero):

| count |
count := 0.
1 to: 1000000 do: [:i | DateAndTime calculateDrift isZero ifFalse: [
count := count +1 ] ].
count / 1000000 asFloat

0.00142

So, "statistically" every ~1000'th request. "DateAndTime now" is wrong
by 1 second than
system time..

-- 
Best regards,
Igor Stasenko.

Reply via email to