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

Classes: Instance, Stopwatch

Constant Summary collapse

VERSION =

Gem version.

"0.1.0"

Class Method Summary collapse

Class Method Details

.clearObject

Clear everything.



16
17
18
19
# File 'lib/elapse.rb', line 16

def self.clear
  instance.clear
  nil
end

.cumulative(sw_key) ⇒ Object

Return sum of all measurements made by the stopwatch.

Elapse.start(:mytime); sleep 0.01; Elapse.stop(:mytime)
Elapse.cumulative(:mytime)   # => 0.01
Elapse.start(:mytime); sleep 0.02; Elapse.stop(:mytime)
Elapse.cumulative(:mytime)   # => 0.03


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