Module: Rex::Stopwatch

Defined in:
lib/rex/stopwatch.rb

Class Method Summary collapse

Class Method Details

.elapsed_time(unit: :float_second) { ... } ⇒ Object

This provides a correct way to time an operation provided within a block.

Parameters:

  • unit (Symbol) (defaults to: :float_second)

    The unit of time in which to measure the duration. The argument is passed to Process.clock_gettime which defines the acceptable values.

Yields:

  • The block whose operation should be timed.

Returns:

  • Returns the result of the block and the elapsed time in the specified unit.

See Also:



15
16
17
18
19
20
21
# File 'lib/rex/stopwatch.rb', line 15

def self.elapsed_time(unit: :float_second)
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit)
  ret = yield
  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) - start

  [ret, elapsed]
end