pwtools.timer.TagTimer

class pwtools.timer.TagTimer(silence=False)[source]

Bases: object

Helper class for timimg. It’s meant to be used for manually inspecting code.

Examples

tt = TagTimer()

# print some message
tt.p('start profiling part 1')
# set start time for tag 'outer-loop'
tt.t('outer-loop')
for i ...
    <code>
    # set start time for tag 'inner-loop'
    tt.t('inner-loop')
    for j ...
        <code>
    # use case 1: get stop time and print timing (stop - start) for tag
    # 'inner-loop' immediately
    tt.pt('inner-loop')
# use case 2: get stop time and store it
tt.t('outer-loop')
<some_more_code>
# print timing (stop - start) for tag 'outer-loop' later (maybe in some
# summary statistic or so)
tt.pt('outer-loop')

# it's possible to re-use tags
tt.p('start profiling part 2')
tt.t('outer-loop')
for i ...
    <code>
    tt.t('inner-loop')
....
__init__(silence=False)[source]

Methods

p(msg)

Simply print msg.

pt(tag[, msg])

Print time difference since last t(tag) call for tag, which is self.time_ar_dict[tag][1] - self.time_ar_dict[tag][0].

t(tag)

Assign and save a numeric value (a time value) in a storage array associated with tag.