Class: Cogger::Time::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/cogger/time/span.rb

Overview

Measures duration of a process with nanosecond precision.

Instance Method Summary collapse

Constructor Details

#initialize(clock = Clock, unit: Unit, range: RANGE) ⇒ Span

Returns a new instance of Span.



7
8
9
10
11
# File 'lib/cogger/time/span.rb', line 7

def initialize clock = Clock, unit: Unit, range: RANGE
  @clock = clock
  @unit = unit
  @range = range
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
# File 'lib/cogger/time/span.rb', line 13

def call
  start = current
  result = yield
  span = current - start

  [result, duration(span), unit.call(span)]
end