
class Time

  # Tracks the elapse time of a code block.
  #
  #   Time.elapse { sleep 1 }  #=> 0.999188899993896
  #
  #--
  # Credit goes to Hal Fulton.
  #++
  def self.elapse
    raise "Need block" unless block_given?
    t0 = Time.now.to_f
    yield
    Time.now.to_f - t0
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCTime < Test::Unit::TestCase

    def test_elapse
      t = Time.elapse { sleep 1 }
      assert( (t > 0.9) && (t < 2.1 ))
    end

  end

=end

