Brian Candler wrote: > Regardless of how well Ruby's sleep worked, this would still be > inaccurate > because of the time needed to execute the other things in the loop. > > Try something like this instead: > > def run > t = Time.now.to_f > 1_000.times do > yield if block_given? > t += 0.01 > interval = t - Time.now.to_f > sleep(interval) if interval > 0 # sleep barfs with negative values > end > end > > t1 = Time.now > run { x = x } > t2 = Time.now > puts t2 - t1 > > Your UDP packets will have a small amount of jitter, which the far end's > jitterbuffer will handle (and if this is going over the Internet, you'll > get > a lot more jitter from other sources), but will be sent at an average > rate > of one every 10ms. > > Brian. Brian, Your solution worked perfectly. The time between packets alternates between 8ms and 12ms, but averages out to 10ms. Thanks for your help. Thanks also to you, Eden. Earle -- Posted via http://www.ruby-forum.com/.