File: elapse.rb

package info (click to toggle)
ruby-facets 2.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,824 kB
  • sloc: ruby: 25,483; xml: 90; makefile: 20
file content (18 lines) | stat: -rw-r--r-- 263 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Time

  # Tracks the elapse time of a code block.
  #
  #   e = Time.elapse { sleep 1 }
  #
  #   e.assert > 1
  #
  # CREDIT: Hal Fulton

  def self.elapse
    raise "Need block" unless block_given?
    t0 = now.to_f
    yield
    now.to_f - t0
  end

end