#asNanoSeconds: のメモ つづき

単に DateAndTime や Time で now で現在時刻を取ってきても ナノ秒オーダーは空ということみたい。

Time now ticks         "print it ==>"  #(0 39112 0)

DateAndTime now ticks  "print it ==>"  #(2454066 39969 0)

「ふみ、じゃあどうしようかな」と言うところで、そういえば プログラムの実行時間計測で、

Time millisecondsToRun: [100 timesRepeat: [100 factorial]]

とかやるなぁと、Time のクラスメソッド millisecondsToRun: の実装をみてみました。

millisecondsToRun: timedBlock 
    "Answer the number of milliseconds timedBlock takes to return its value."

    | initialMilliseconds |
    initialMilliseconds _ self millisecondClockValue.
    timedBlock value.
    ^self millisecondsSince: initialMilliseconds

なるほど、millisecondClockValue ですか。実験。

30 timesRepeat: [(Delay forMilliseconds: 100) wait.
                Transcript cr; show: DateAndTime now.
                Transcript show:' -- '; show: Time millisecondClockValue]

結果。

2006-11-26T11:15:03+00:00 -- 183511938
2006-11-26T11:15:03+00:00 -- 183512096
2006-11-26T11:15:04+00:00 -- 183512257
2006-11-26T11:15:04+00:00 -- 183512419
2006-11-26T11:15:04+00:00 -- 183512584
2006-11-26T11:15:04+00:00 -- 183512753
2006-11-26T11:15:04+00:00 -- 183512922
2006-11-26T11:15:04+00:00 -- 183513096
2006-11-26T11:15:05+00:00 -- 183513273
2006-11-26T11:15:05+00:00 -- 183513449
2006-11-26T11:15:05+00:00 -- 183513625
2006-11-26T11:15:05+00:00 -- 183513802
2006-11-26T11:15:05+00:00 -- 183513976
2006-11-26T11:15:05+00:00 -- 183514153
2006-11-26T11:15:06+00:00 -- 183514329
2006-11-26T11:15:06+00:00 -- 183514505
2006-11-26T11:15:06+00:00 -- 183514683
2006-11-26T11:15:06+00:00 -- 183514865
2006-11-26T11:15:06+00:00 -- 183515040
2006-11-26T11:15:07+00:00 -- 183515215
2006-11-26T11:15:07+00:00 -- 183515390
2006-11-26T11:15:07+00:00 -- 183515567
2006-11-26T11:15:07+00:00 -- 183515742
2006-11-26T11:15:07+00:00 -- 183515920
2006-11-26T11:15:07+00:00 -- 183516097

OK。これでやりたいことが出来ます。

・・・それにしても、ちょっと何かを作りたいと思っていつものように思わぬところで躓いてしまう。Smalltalk環境は調べるの楽だから全然苦ではないのですが、いつまで経っても エセSmalltalker のまんまですね〜 orz