Class: Jinx::Stopwatch::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/jinx/helpers/stopwatch.rb

Overview

Time accumulates elapsed real time and total CPU time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tms = nil) ⇒ Time

Returns a new instance of Time.

Parameters:

  • the (Benchmark::Tms, nil)

    starting time (default is now)



12
13
14
# File 'lib/jinx/helpers/stopwatch.rb', line 12

def initialize(tms=nil)
  @tms = tms || Benchmark::Tms.new
end

Instance Attribute Details

#tmsBenchmark::Tms (readonly)

Returns the Tms wrapped by this Time.

Returns:

  • (Benchmark::Tms)

    the Tms wrapped by this Time



9
10
11
# File 'lib/jinx/helpers/stopwatch.rb', line 9

def tms
  @tms
end

Instance Method Details

#cpuObject

@return [Numeric] the cumulative CPU total time



22
23
24
# File 'lib/jinx/helpers/stopwatch.rb', line 22

def cpu
  @tms.total
end

#elapsedNumeric

Returns the cumulative elapsed real clock time.

Returns:

  • (Numeric)

    the cumulative elapsed real clock time



17
18
19
# File 'lib/jinx/helpers/stopwatch.rb', line 17

def elapsed
  @tms.real
end

#resetObject

Sets this benchmark timer to zero.



36
37
38
# File 'lib/jinx/helpers/stopwatch.rb', line 36

def reset
  @tms = Benchmark::Tms.new
end

#split(&block) ⇒ Object

Adds the time to execute the given block to this time.

@return [Numeric] the split execution Time


29
30
31
32
33
# File 'lib/jinx/helpers/stopwatch.rb', line 29

def split(&block)
  stms = Benchmark.measure(&block)
  @tms += stms
  Time.new(stms)
end