Class: Cosmo::Utils::Stopwatch

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

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

#clock_timeFloat

Returns:

  • (Float)


27
28
29
# File 'lib/cosmo/utils/stopwatch.rb', line 27

def clock_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
end

#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

#resetvoid

This method returns an undefined value.



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

def reset
  @started_at = clock_time
end