Class: Monotonic::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/Monotonic/Timer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.time(&block) ⇒ Object



11
12
13
14
# File 'lib/Monotonic/Timer.rb', line 11

def time(&block)
  timer = Timer.new
  timer.time(&block)
end

Instance Method Details

#startObject

class << self



18
19
20
21
# File 'lib/Monotonic/Timer.rb', line 18

def start
  @finish_time = nil
  @start_time = Monotonic::Time.now
end

#stopObject



23
24
25
# File 'lib/Monotonic/Timer.rb', line 23

def stop
  @finish_time = Monotonic::Time.now
end

#timeObject



35
36
37
38
39
40
41
# File 'lib/Monotonic/Timer.rb', line 35

def time
  start
  yield self
ensure
  stop
  return total_time
end

#total_timeObject



27
28
29
30
31
32
33
# File 'lib/Monotonic/Timer.rb', line 27

def total_time
  if @finish_time
    @finish_time - @start_time
  else
    Monotonic::Time.now - @start_time
  end
end