I noticed that ruby uses a different way to sleep with values >1e-6s.
I added my observations below. My question is now: what is the suggested
way to sleep e.g. 0.001s?
10000.times { sleep(0.0000001) }? Cant' really be it, no? :)

The results:
$ ruby sleeper.rb
100x sleeping 0.01000000s: 0.01003044s per sleep, runtime: 1.00304s
100x sleeping 0.00100000s: 0.01006163s per sleep, runtime: 1.00616s
100x sleeping 0.00010000s: 0.01007538s per sleep, runtime: 1.00754s
100x sleeping 0.00001000s: 0.01011209s per sleep, runtime: 1.01121s
100x sleeping 0.00000100s: 0.01008325s per sleep, runtime: 1.00832s
100x sleeping 0.00000010s: 0.00001131s per sleep, runtime: 0.00113s
100x sleeping 0.00000001s: 0.00000986s per sleep, runtime: 0.00099s

The sleeper.rb file:
#!/usr/bin/ruby

def bench(n=1, &b)
  start = Time.now
  n.to_i.times(&b)
  Time.now-start
end

[0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, 0.00000001].each {
|s|
  r = bench(100) { sleep(s) }
  printf "100x sleeping %.8fs: %.8fs per sleep, runtime: %.5fs\n", s,
r/100, r
}

Regards
Stefan

-- 
Posted via http://www.ruby-forum.com/.