Class: Cosmo::Utils::Stopwatch

Inherits:
Object
  • Object
show all
Defined in:
lib/cosmo/utils/stopwatch.rb

Instance Method Summary collapse

Constructor Details

#initializeStopwatch

Returns a new instance of Stopwatch.



6
7
8
# File 'lib/cosmo/utils/stopwatch.rb', line 6

def initialize
  reset
end

Instance Method Details

#elapsed_millisFloat

Returns A number of elapsed milliseconds.

Returns:

  • (Float)

    A number of elapsed milliseconds



11
12
13
# File 'lib/cosmo/utils/stopwatch.rb', line 11

def elapsed_millis
  (clock_time - @started_at).round(2)
end

#elapsed_secondsFloat

Returns A number of elapsed seconds.

Returns:

  • (Float)

    A number of elapsed seconds



16
17
18
# File 'lib/cosmo/utils/stopwatch.rb', line 16

def elapsed_seconds
  (elapsed_millis / 1_000).round(2)
end

#resetObject



20
21
22
# File 'lib/cosmo/utils/stopwatch.rb', line 20

def reset
  @started_at = clock_time
end