Timer

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=1]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; "abjad.system.ContextManager.ContextManager" [URL="../api/abjad/system/ContextManager.html#abjad.system.ContextManager.ContextManager", label="Context\nManager", shape=oval, style=bold, target=_top]; "abjad.system.Timer.Timer" [URL="../api/abjad/system/Timer.html#abjad.system.Timer.Timer", color=black, fontcolor=white, label=Timer, target=_top]; "abjad.system.AbjadObject.AbjadObject" -> "abjad.system.ContextManager.ContextManager"; "abjad.system.ContextManager.ContextManager" -> "abjad.system.Timer.Timer"; } subgraph cluster_builtins { graph [label=builtins]; node [color=2]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; }

class abjad.system.Timer.Timer(exit_message=None, enter_message=None, print_continuously_from_background=False, verbose=True)

A timing context manager.

>>> timer = abjad.Timer()
>>> with timer:
...     for _ in range(1000000):
...         x = 1 + 1
...
>>> timer.elapsed_time 
0.092742919921875

The timer can also be accessed from within the with block:

>>> with abjad.Timer() as timer: 
...     for _ in range(5):
...         for _ in range(1000000):
...             x = 1 + 1
...         print(timer.elapsed_time)
...
0.101150989532
0.203935861588
0.304930925369
0.4057970047
0.50649189949

Timers can be reused between with blocks. They will reset their clock on entering any with block.


Attributes Summary

__enter__ Enters context manager.
__exit__ Exist context manager.
elapsed_time Elapsed time.
enter_message Timer enter message.
exit_message Timer exit message.
print_continuously_from_background Is true when timer should print continuously from background.
start_time Start time of timer.
stop_time Stop time of timer.
total_time_message Gets total time message.
verbose Is true if timer should print messages.

Special methods

__enter__()

Enters context manager.

Returns context manager.

__exit__(exc_type, exc_value, traceback)

Exist context manager.

Returns none.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.


Read-only properties

elapsed_time

Elapsed time.

Return float or none.

enter_message

Timer enter message.

Returns string.

exit_message

Timer exit message.

Returns string.

print_continuously_from_background

Is true when timer should print continuously from background.

Returns true or false.

start_time

Start time of timer.

Returns time.

stop_time

Stop time of timer.

Returns time.

total_time_message

Gets total time message.

Truncated to the nearest second.

Returns string.

verbose

Is true if timer should print messages.

Returns true or false.