Module: Elapse
- Defined in:
- lib/elapse.rb,
lib/elapse/version.rb,
lib/elapse/instance.rb,
lib/elapse/stopwatch.rb
Overview
Elapsed time measurement tool
See rubydoc documentation for basic usage examples.
Defined Under Namespace
Constant Summary collapse
- VERSION =
Gem version.
"0.1.0"
Class Method Summary collapse
-
.clear ⇒ Object
Clear everything.
-
.cumulative(sw_key) ⇒ Object
Return sum of all measurements made by the stopwatch.
-
.reset(sw_key) ⇒ Object
Reset the named stopwatch.
-
.start(sw_key = nil) ⇒ Object
Start the stopwatch.
-
.stop(sw_key = nil) ⇒ Object
Stop the stopwatch.
-
.took(sw_key = nil, &block) ⇒ Object
Return time of the last stopwatch measurement.
Class Method Details
.clear ⇒ Object
Clear everything.
16 17 18 19 |
# File 'lib/elapse.rb', line 16 def self.clear instance.clear nil end |
.cumulative(sw_key) ⇒ Object
27 28 29 |
# File 'lib/elapse.rb', line 27 def self.cumulative(sw_key) instance.cumulative(sw_key) end |
.reset(sw_key) ⇒ Object
Reset the named stopwatch.
Elapse.reset(:mytime)
34 35 36 |
# File 'lib/elapse.rb', line 34 def self.reset(sw_key) instance.reset(sw_key) end |
.start(sw_key = nil) ⇒ Object
Start the stopwatch. Return Time::now.
start # Stacked mode.
start(:mytime) # Named mode.
42 43 44 |
# File 'lib/elapse.rb', line 42 def self.start(sw_key = nil) instance.start(sw_key) end |
.stop(sw_key = nil) ⇒ Object
Stop the stopwatch. Return Time::now.
stop # Stacked mode.
stop(:mytime) # Named mode.
50 51 52 |
# File 'lib/elapse.rb', line 50 def self.stop(sw_key = nil) instance.stop(sw_key) end |
.took(sw_key = nil, &block) ⇒ Object
Return time of the last stopwatch measurement. If the stopwatch is running, stop it.
Stacked mode:
start
sleep 0.01
took # => 0.01
Named mode:
start(:mytime)
sleep 0.01
took(:mytime) # => 0.01
Block execution, stacked mode:
took {sleep 0.01} # => 0.01
Block execution, named mode:
took(:mytime) {sleep 0.01} # => 0.01
75 76 77 |
# File 'lib/elapse.rb', line 75 def self.took(sw_key = nil, &block) instance.took(sw_key, &block) end |