From: "evanwebb@..." Date: 2007-04-27T15:45:14+09:00 Subject: Re: 10 millisecond delay/callback It's unlikely to get 10ms intervals reliably even in C, so getting it in ruby is very unlikely. The reason it's hard to get it even in C is (as man setitimer says): "Time values smaller than the resolution of the system clock are rounded up to this resolution (typically 10 milliseconds)." Even taking the system clock resolution out of the equation, if the GC kicks in, it will definitely cause a delay greater than 10ms. Add in the rest of the delays caused by ruby's runtime, and it's a loosing game. If you require running a loop at 10ms intervals, you're probably going to have to dip down into C. - Evan Phoenix On Apr 26, 12:57 pm, Earle Clubb wrote: > I need to perform a task every 10ms. I've been using > kernel.sleep(0.01), but sleep seems to be slow and erratic at sub-second > resolutions. Here's a test I ran along with the results: > > irb(main):001:0> 0.upto(25) do > irb(main):002:1* puts Time.now.usec/1000 > irb(main):003:1> STDOUT.flush > irb(main):004:1> sleep 0.01 > irb(main):005:1> end > 105 > 132 > 143 > 162 > 191 > 205 > 219 > 238 > 257 > 277 > 294 > 311 > 330 > 354 > 366 > 385 > 412 > 431 > 450 > 468 > 488 > 504 > 522 > 542 > 556 > 581 > => 0 > irb(main):006:0> > > So I'm wondering if there's a way to get a steady 10ms delay. Another > option would be to set up an alarm or scheduled callback or something > every 10ms. Is this possible. > > Thanks, > Earle > > -- > Posted viahttp://www.ruby-forum.com/.