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'
>>>
... t.start("kaylee", "river", "inara")
>>> sleep(3)
>>> 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.
>>>
... 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]
>>>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_loggable_timestamp(self)
Human-readable by intent |
source code
|
|
|
|
|
|
Inherited from object:
__delattr__,
__format__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__str__,
__subclasshook__
|
|
Inherited from object:
__class__
|
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
- (inherited documentation)
|