Class: Dry::Monitor::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/monitor/clock.rb

Instance Method Summary collapse

Constructor Details

#initialize(unit: :millisecond) ⇒ Clock

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Clock.



8
9
10
# File 'lib/dry/monitor/clock.rb', line 8

def initialize(unit: :millisecond)
  @unit = unit
end

Instance Method Details

#currentObject



20
21
22
# File 'lib/dry/monitor/clock.rb', line 20

def current
  Process.clock_gettime(Process::CLOCK_MONOTONIC, @unit)
end

#measureObject



13
14
15
16
17
# File 'lib/dry/monitor/clock.rb', line 13

def measure
  start = current
  result = yield
  [result, current - start]
end