Class: Fable::Profiler::Stopwatch

Inherits:
Object
  • Object
show all
Defined in:
lib/fable/profiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStopwatch

Returns a new instance of Stopwatch.



250
251
252
# File 'lib/fable/profiler.rb', line 250

def initialize
  @elapsed_milliseconds = 0
end

Instance Attribute Details

#elapsed_millisecondsObject

Returns the value of attribute elapsed_milliseconds.



248
249
250
# File 'lib/fable/profiler.rb', line 248

def elapsed_milliseconds
  @elapsed_milliseconds
end

#start_timeObject

Returns the value of attribute start_time.



248
249
250
# File 'lib/fable/profiler.rb', line 248

def start_time
  @start_time
end

#stop_timeObject

Returns the value of attribute stop_time.



248
249
250
# File 'lib/fable/profiler.rb', line 248

def stop_time
  @stop_time
end

Instance Method Details

#elapsed_from_start_to_stopObject



282
283
284
# File 'lib/fable/profiler.rb', line 282

def elapsed_from_start_to_stop
  ((@stop_time || Time.now.utc).to_r - @start_time.to_r) * 1000.0
end

#reset!Object



259
260
261
# File 'lib/fable/profiler.rb', line 259

def reset!
  @elapsed_milliseconds = 0
end

#restart!Object



263
264
265
266
# File 'lib/fable/profiler.rb', line 263

def restart!
  reset!
  start!
end

#start!Object



254
255
256
257
# File 'lib/fable/profiler.rb', line 254

def start!
  @stop_time = nil
  @start_time = Time.now.utc
end

#stop!Object



268
269
270
271
# File 'lib/fable/profiler.rb', line 268

def stop!
  @stop_time = Time.now.utc
  @elapsed_milliseconds += elapsed_from_start_to_stop
end