Package sword2 :: Module utils :: Class Timer
[hide private]
[frames] | no frames]

Class Timer

source code


Simple timer, providing a 'stopwatch' mechanism.

Usage example:

>>> from sword2.utils import Timer
>>> from time import sleep
>>> t = Timer()
>>> t.get_timestamp()
datetime.datetime(2011, 6, 7, 7, 40, 53, 87248)
>>> t.get_loggable_timestamp()
'2011-06-07T07:40:53.087516'
>>> # Start a few timers
... t.start("kaylee", "river", "inara")
>>> sleep(3)   # wait a little while
>>> t.time_since_start("kaylee")
(0, 3.0048139095306396)

# tuple -> (index of the logged .duration, time since the .start method was called) # eg 't.duration['kaylee'][0]' would equal 3.00481....

>>> sleep(2)
>>> t.time_since_start("kaylee", "inara")
[(1, 5.00858998298645), (0, 5.00858998298645)]
>>> sleep(5)
>>> t.time_since_start("kaylee", "river")
[(2, 10.015379905700684), (0, 10.015379905700684)]
>>> sleep(4)
>>> t.time_since_start("kaylee", "inara", "river")
[(3, 14.021538972854614), (1, 14.021538972854614), (1, 14.021538972854614)]

# The order of the response is the same as the order of the names in the method call.

>>> # report back
... t.duration['kaylee']
[3.0048139095306396, 5.00858998298645, 10.015379905700684, 14.021538972854614]
>>> t.duration['inara']
[5.00858998298645, 14.021538972854614]
>>> t.duration['river']
[10.015379905700684, 14.021538972854614]
>>>
Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
reset_all(self) source code
 
reset(self, name) source code
 
read_raw(self, name) source code
 
read(self, name) source code
 
start(self, *args) source code
 
stop(self, *args) source code
 
get_timestamp(self) source code
 
get_loggable_timestamp(self)
Human-readable by intent
source code
 
time_since_start(self, *args) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)