Class: Contrast::Utils::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/utils/timer.rb

Overview

Timer is class that can track state about when an event starts and how long it takes Also containes utility methods to get time values in milliseconds

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now) ⇒ Timer

Returns a new instance of Timer.



11
12
13
14
15
# File 'lib/contrast/utils/timer.rb', line 11

def initialize time = Time.now
  @start_at = time
  @start_ms = (@start_at.to_f * 1000).to_i
  @events = {}
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



9
10
11
# File 'lib/contrast/utils/timer.rb', line 9

def events
  @events
end

#start_msObject (readonly)

Returns the value of attribute start_ms.



9
10
11
# File 'lib/contrast/utils/timer.rb', line 9

def start_ms
  @start_ms
end

Class Method Details

.now_msObject



17
18
19
# File 'lib/contrast/utils/timer.rb', line 17

def self.now_ms
  (Time.now.to_f * 1000).to_i
end