(class from pyomo.common.timing)
pyomo.common.timing
Bases: object
object
A class to calculate and report elapsed time.
Examples
>>> from pyomo.common.timing import TicTocTimer >>> timer = TicTocTimer() >>> timer.tic('starting timer') # starts the elapsed time timer (from 0) [ 0.00] starting timer >>> # ... do task 1 >>> dT = timer.toc('task 1') [+ 0.00] task 1 >>> print("elapsed time: %0.1f" % dT) elapsed time: 0.0
If no ostream or logger is provided, then output is printed to sys.stdout
ostream (FILE) – an optional output stream to print the timing information
logger (Logger) – an optional output stream using the python logging package. Note: the timing logged using logger.info()
logger.info()
Methods
__init__([ostream, logger])
__init__
start()
start
stop()
stop
tic([msg, ostream, logger, level])
tic
Reset the tic/toc delta timer.
toc([msg, delta, ostream, logger, level])
toc
Print out the elapsed time.
Member Documentation
This resets the reference time from which the next delta time is calculated to the current time.
msg (str) – The message to print out. If not specified, then prints out “Resetting the tic/toc delta timer”; if msg is None, then no message is printed.
*args (tuple) – optional positional arguments used for %-formatting the msg
ostream (FILE) – an optional output stream (overrides the ostream provided when the class was constructed).
logger (Logger) – an optional output stream using the python logging package (overrides the ostream provided when the class was constructed). Note: timing logged using logger.info
level (int) – an optional logging output level.
msg (str) – The message to print out. If not specified, then print out the file name, line number, and function that called this method; if msg is None, then no message is printed.
delta (bool) – print out the elapsed wall clock time since the last call to tic() (False) or since the most recent call to either tic() or toc() (True (default)).
tic()
False
toc()
True
logger (Logger) – an optional output stream using the python logging package (overrides the ostream provided when the class was constructed). Note: timing logged using level