Class: Jinx::Stopwatch
Overview
Stopwatch is a simple execution time accumulator.
Defined Under Namespace
Classes: Time
Class Method Summary collapse
-
.measure(&block) ⇒ Numeric
Executes the given block.
Instance Method Summary collapse
-
#cpu ⇒ Numeric
The cumulative CPU total time spent in #run executions for the current process and its children.
-
#elapsed ⇒ Numeric
The cumulative elapsed real clock time spent in #run executions.
-
#initialize ⇒ Stopwatch
constructor
Creates a new idle Stopwatch.
-
#reset ⇒ Object
Resets this Stopwatch’s cumulative time to zero.
-
#run(&block) ⇒ Object
Executes the given block.
Constructor Details
Class Method Details
.measure(&block) ⇒ Numeric
Executes the given block
44 45 46 |
# File 'lib/jinx/helpers/stopwatch.rb', line 44 def self.measure(&block) new.run(&block) end |
Instance Method Details
#cpu ⇒ Numeric
Returns the cumulative CPU total time spent in #run executions for the current process and its children.
67 68 69 |
# File 'lib/jinx/helpers/stopwatch.rb', line 67 def cpu @time.cpu end |
#elapsed ⇒ Numeric
Returns the cumulative elapsed real clock time spent in #run executions.
61 62 63 |
# File 'lib/jinx/helpers/stopwatch.rb', line 61 def elapsed @time.elapsed end |
#reset ⇒ Object
Resets this Stopwatch’s cumulative time to zero.
72 73 74 |
# File 'lib/jinx/helpers/stopwatch.rb', line 72 def reset @time.reset end |
#run(&block) ⇒ Object
Executes the given block. Accumulates the execution time in this Stopwatch.
@return [Numeric] the execution run Time
56 57 58 |
# File 'lib/jinx/helpers/stopwatch.rb', line 56 def run(&block) @time.split(&block) end |