title: Timer in Ruby performance
body: <p>I was looking for an online example demonstrating a timer in ruby and came across the code below.
  It works as expected but does it make sense that this simple program uses 30Mo of memory (as shown in windows task manager) and way too much CPU?</p>
  
  <p>Thanks a lot</p>
  
  <pre><code>def time_block
    start_time = Time.now
    Thread.new { yield }
    Time.now - start_time
  end
  
  def repeat_every(seconds)
    while true do
      time_spent = time_block { yield } # To handle -ve sleep interaval
      sleep(seconds - time_spent) if time_spent &lt; seconds
    end
  end
  
  repeat_every(5) {
  }
  </code></pre>