Sha256: 9ba3ff5d696362ba36df84e78abba1099274b0fc2a31875122e2a31b36695060

Contents?: true

Size: 515 Bytes

Versions: 1

Compression:

Stored size: 515 Bytes

Contents

module Rex

  # This provides a correct way to time an operation provided within a block.
  #
  # @see https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/
  #
  # @yield [] The block whose operation should be timed.
  #
  # @return Returns the result of the block and the elapsed time in seconds.
  def self.stopwatch
    start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    ret = yield
    elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start

    [ret, elapsed]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rex-core-0.1.19 lib/rex/stopwatch.rb