sleep
多くの人はfloat 値を取ることを知りません:
Suspends the current thread for duration seconds (which may be
any number, including a Float with fractional seconds). Returns the actual
number of seconds slept (rounded), which may be less than that asked for if
another thread calls Thread#run. Called without an argument, sleep() will
sleep forever.
Time.new #=> 2008-03-08 19:56:19 +0900
sleep 1.2 #=> 1
Time.new #=> 2008-03-08 19:56:20 +0900
sleep 1.9 #=> 2
Time.new #=> 2008-03-08 19:56:22 +0900
遅延が正確であるという保証はありません。
3.times do
t1 = Time.now.to_f
sleep 0.5
t2 = Time.now.to_f
puts t2 - t1
end
結果:
0.501162052154541
0.5010881423950195
0.5001001358032227
追加のタスクを実行すると、おそらくそのスキューがさらに大きくなります。