Bases: onyx.builtin.ordered_wormattrdict
A simple class for tracking wall and CPU times. A TimeDict holds pairs of times as generated by time.time() and time.clock() in a dictionary with client-provided keys. NB!! - the values returned by clock() may be platform dependent. In particular, MacOSX and Linux may not be using the same scale.
XXX Would be nice if there were a way to access the system value CLOCKS_PER_SEC, but I haven’t found one
>>> td0 = TimeDict()
>>> td0.add_time_mark('a')
>>> sleep_atleast(0.25)
>>> td0.add_time_mark('b')
>>> td0
TimeDict([('a', TimeDictTuple(wall_time=..., cpu_time=...)), ('b', TimeDictTuple(wall_time=..., cpu_time=...))])
>>> wall_a, cpu_a = td0['a']
>>> wall_b, cpu_b = td0['b']
>>> wall_a + 0.25 <= wall_b
True
>>> cpu_a <= cpu_b
True
>>> wall_a2 = td0['a'].wall_time
>>> wall_a2 is wall_a
True
>>> cpu_a2 = td0['a'].cpu_time
>>> cpu_a2 is cpu_a
True
Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary.
OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S and values equal to v (which defaults to None).
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
D.has_key(k) -> True if D has a key k, else False
od.viewitems() -> a set-like object providing a view on od’s items
od.viewkeys() -> a set-like object providing a view on od’s keys
od.viewvalues() -> an object providing a view on od’s values
Bases: tuple
TimeDictTuple(wall_time, cpu_time)
T.count(value) -> integer – return number of occurrences of value
Alias for field number 1
T.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.
Alias for field number 0
Deterministic sleep function. This works around a possible problem with time.sleep(): ‘The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine.’ (from the doc for time.sleep)