Sha256: e9620240a57e8bb0190eaae9a54ae378f0ca451d9666257ddecb4e46a56d1f27

Contents?: true

Size: 754 Bytes

Versions: 10

Compression:

Stored size: 754 Bytes

Contents

# = FILE
#
#   time/change.rb
#
# = DESCRIPTION
#
#   Time extension for changing time.
#
# = AUTHORS
#
#   CREDIT Thomas Sawyer

#
class Time

  # Tracks the elapse time of a code block.
  #
  #   Time.elapse { sleep 1 }  #=> 0.999188899993896
  #
  #--
  # CREDIT 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 TestTime < Test::Unit::TestCase

    def test_elapse
      #t = Time.parse('4/20/2006 15:37')
      t = Time.elapse { sleep 1 }
      assert( (t > 0.9) && (t < 2.1 ))
    end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.0.0 lib/core/facets/time/elapse.rb
facets-2.0.1 lib/core/facets/time/elapse.rb
facets-2.0.2 lib/core/facets/time/elapse.rb
facets-2.1.0 lib/core/facets/time/elapse.rb
facets-2.1.1 lib/core/facets/time/elapse.rb
facets-2.1.2 lib/core/facets/time/elapse.rb
facets-2.0.5 lib/core/facets/time/elapse.rb
facets-2.0.3 lib/core/facets/time/elapse.rb
facets-2.0.4 lib/core/facets/time/elapse.rb
facets-2.1.3 lib/core/facets/time/elapse.rb