Sha256: e572fbe0db1feb303a60bce4d1baa2f7f760d141d57a65de6bfd3558a7fedcc7

Contents?: true

Size: 878 Bytes

Versions: 23

Compression:

Stored size: 878 Bytes

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module Performance
  class Timer
    attr_accessor :start_timestamp, :stop_timestamp

    def initialize
      @start_timestamp = nil
      @stop_timestamp = nil
    end

    def start(t=Time.now)
      @start_timestamp = t
    end

    def stopped?
      !!@stop_timestamp
    end

    def stop(t=Time.now)
      @stop_timestamp = t
    end

    def measure
      start
      yield
      stop
    end

    def elapsed
      if @stop_timestamp && @start_timestamp
        @stop_timestamp - @start_timestamp
      else
        nil
      end
    end

    def inspect
      "<Performance::Timer @start_timestamp=#{start_timestamp.inspect}, @stop_timestamp=#{stop_timestamp.inspect}, elapsed=#{elapsed}>"
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
newrelic_rpm-3.9.4.245 test/performance/lib/performance/timer.rb
newrelic_rpm-3.9.3.241 test/performance/lib/performance/timer.rb
newrelic_rpm-3.9.2.239 test/performance/lib/performance/timer.rb
newrelic_rpm-3.9.1.236 test/performance/lib/performance/timer.rb
newrelic_rpm-3.9.0.229 test/performance/lib/performance/timer.rb
newrelic_rpm-3.8.1.221 test/performance/lib/performance/timer.rb
newrelic_rpm-3.8.0.218 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.3.204 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.3.199 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.2.195 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.2.192 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.2.190.beta test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.1.188 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.1.182 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.1.180 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.0.177 test/performance/lib/performance/timer.rb
newrelic_rpm-3.7.0.174.beta test/performance/lib/performance/timer.rb
newrelic_rpm-3.6.9.171 test/performance/lib/performance/timer.rb
newrelic_rpm-3.6.8.168 test/performance/lib/performance/timer.rb
newrelic_rpm-3.6.8.164 test/performance/lib/performance/timer.rb