Ex. 1.23
http://d.hatena.ne.jp/yukichanko/20090827/1251388975
不思議。 確かに runtime 実行オーバーヘッド分 t とnext-*を呼ぶ分がプラスされてしまうのは当然なんだけど、そんなん誤差だろうし。
(let ((s (runtime))) (- (runtime) s))
とりあえず、profileをとってみるのはどうでしょう?
僕のところではこんな感じで良さそうな結果になっているっぽ。
gosh> (begin (profiler-reset) (profiler-start) (prime? 100000000003) (profiler-stop) (profiler-show)) Profiler statistics (total 44 samples, 0.44 seconds) num time/ total Name calls call(ms) samples ---------------------------------------------------+------+-------+----------- remainder 316226 0.0008 26( 59%) square 316227 0.0003 11( 25%) find-divisor 316227 0.0002 6( 14%) divides? 316226 0.0000 1( 2%) prime? 1 0.0000 0( 0%) profiler-stop 1 0.0000 0( 0%) #<undef> gosh> (begin (profiler-reset) (profiler-start) (prime?-half 100000000003) (profiler-stop) (profiler-show)) Profiler statistics (total 25 samples, 0.25 seconds) num time/ total Name calls call(ms) samples ---------------------------------------------------+------+-------+----------- next-divisor 158114 0.0008 13( 52%) remainder 158114 0.0004 7( 28%) square 158115 0.0003 4( 16%) divides? 158114 0.0001 1( 4%) find-divisor-half 158115 0.0000 0( 0%) prime?-half 1 0.0000 0( 0%) profiler-stop 1 0.0000 0( 0%) #<undef>
(MacBookで計り直してみた)
誤差でもなかった。
で、実際どうなってるか結構興味がある。