schrodinger.application.desmond.packages.timer module¶
Facilities for timing a block of code. Copyright Schrodinger, LLC. All rights reserved.
Example usage:
from schrodinger.application.desmond.packages.timer import timer
- with timer(“Reading the trajectory…”):
traj.read_trj(trj_fname)
Example output:
- Reading the trajectory…
100 frames Done. (0.5 sec)
In this example, we have three lines in output. Line#1 is the start message, and
line#3 is the timing message. The start-message and the format for the timing
message can be customed by the message
and fmt
arguments, respectively.
Arguments for timer
:
- type message
str
orNone
- type message
The message to print out before the timing starts. Default is
None
– no message will be printed.- type fmt
str
- type fmt
The format to print out the timing. Default is “Done. (%.2f sec)”. A custom format should contain 1 floating number control paramter.
- type threshold
float
- param threshold
Specifies a threshold. If the elapsed time is less than
threshold
, no timing message will not be printed out.- type record
list
orNone
- param record
If a list value is given, the current elapsed time will be appended to the list. This is handy if you want to accumulate the elapsed times.
- type logger
A callable object.
- param logger
Function called to print the messages.
-
class
schrodinger.application.desmond.packages.timer.
Timer
(message=None, threshold=0.1, fmt=' Done. (%.2f sec)', record=None, logger=<function _default_logger>)[source]¶ Bases:
object
You can use this class to create your own timer function with custom default behavior.
Example usage:
from schrodinger.application.desmond.packages.timer import Timer
mytimer = Timer(threshold=0.2) # Creates a timer with 0.2 threshold.
- with mytimer(“Reading the trajectory…”):
traj.read_trj(trj_fname)
In this example,
mytimer
behaves exactly the same as the standardtimer
(see the docstring of this module) except for the default value ofthreshold
parameter that has been customed to 0.2.-
class
Args
(message, threshold, fmt, record, logger)¶ Bases:
tuple
-
__contains__
(key, /)¶ Return key in self.
-
__len__
()¶ Return len(self).
-
count
(value, /)¶ Return number of occurrences of value.
-
fmt
¶ Alias for field number 2
-
index
(value, start=0, stop=9223372036854775807, /)¶ Return first index of value.
Raises ValueError if the value is not present.
-
logger
¶ Alias for field number 4
-
message
¶ Alias for field number 0
-
record
¶ Alias for field number 3
-
threshold
¶ Alias for field number 1
-