On Apr 15, 2013, at 3:25 PM, Igor Stasenko wrote:
On 15 April 2013 12:14, Henrik Johansen <henrik.s.johansen@veloxit.no> wrote:
On Apr 13, 2013, at 12:16 AM, Igor Stasenko wrote:
But that's fine.. now look at
secondsWhenClockTicks
"waits for the moment when a new second begins"
| lastSecond |
lastSecond := self primSecondsClock. [ lastSecond = self primSecondsClock ] whileTrue: [ (Delay forMilliseconds: 1) wait ].
^ lastSecond + 1
that is complete nonsense. Sorry.
This code relying on primSecondsClock resolution, which is..... (drum roll..... ) 1 second..
then it is combined with millisecondClockValue , as you see later to get system time with millisecond precision..
I am not genius in math and physics.. but even i understand that if you measurement has error X you cannot get more precision than X, even if you combine it with another measurement with higher precision.
(But i can be wrong with that.. if so, please explain why)
Because, as Levente said in code, resolution != accuracy. When you measure a single sample, sure, that value has an error of max resolution / 2. But when you measure when that value _changes_, you have an error of the underlying accuracy / 2. Clock s value: 1 2 resolution: |_______|_______| accuracy: ||||||||||||||||||||||||||||||||||| ^ Here's to hoping the above ascii art(?) worked!
So no, that method is not complete nonsense.
Okay. Now i rewriting the code which uses new primitive (primUTCMicrosecondClock), and then we will no longer need this startup logic nor wrap around check & other gory details... just use a primitive.
Sounds clearer, yes. However, be aware, at least on my VM: [Time millisecondClockValue] bench '34,600,000 per second.' [Time primUTCMicrosecondClock] bench '12,400,000 per second.' Which in my case translated to that in a Time2 class with #now defined: now | microSecondsToday | microSecondsToday := self primUTCMicrosecondClock \\ 86400000000. ^ self seconds: microSecondsToday // 1000000 nanoSeconds: microSecondsToday * 1000 and changing the relatively low-hanging fruit in standard Time (removing Duration creation and other crap): seconds: seconds nanoSeconds: nanoCount "Answer a Time from midnight." ^ self basicNew seconds: seconds nanoSeconds: nanoCount To benchmarks that looked like this: "Old code" [Time now ] bench '7,330,000 per second.' '7,280,000 per second.' '7,170,000 per second.' "Using microsecondClock every call" [Time2 now ] bench '2,280,000 per second.''2,300,000 per second.' '2,180,000 per second.' Also note, Time2 lacked translation to Local time, which would be needed for consistency with Time now. Cheers, Henry