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 or None |
|
| 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 or None |
|
| 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>)¶ Bases:
objectYou 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,
mytimerbehaves exactly the same as the standardtimer(see the docstring of this module) except for the default value ofthresholdparameter that has been customed to 0.2.-
class
Args(message, threshold, fmt, record, logger)¶ Bases:
tuple-
__add__¶ Return self+value.
-
__class__¶ alias of
builtins.type
-
__contains__¶ Return key in self.
-
__delattr__¶ Implement delattr(self, name).
-
__dir__() → list¶ default dir() implementation
-
__eq__¶ Return self==value.
-
__format__()¶ default object formatter
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__¶ Return self[key].
-
__getnewargs__()¶ Return self as a plain tuple. Used by copy and pickle.
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init__¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__module__= 'schrodinger.application.desmond.packages.timer'¶
-
__mul__¶ Return self*value.n
-
__ne__¶ Return self!=value.
-
static
__new__(_cls, message, threshold, fmt, record, logger)¶ Create new instance of Args(message, threshold, fmt, record, logger)
-
__reduce__()¶ helper for pickle
-
__reduce_ex__()¶ helper for pickle
-
__repr__()¶ Return a nicely formatted representation string
-
__rmul__¶ Return self*value.
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__() → int¶ size of object in memory, in bytes
-
__slots__= ()¶
-
__str__¶ Return str(self).
-
__subclasshook__()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
count(value) → integer -- return number of occurrences of value¶
-
fmt¶ Alias for field number 2
-
index(value[, start[, stop]]) → integer -- 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
-
-
__init__(message=None, threshold=0.1, fmt=' Done. (%.2f sec)', record=None, logger=<function _default_logger>)¶ Initialize self. See help(type(self)) for accurate signature.
-
__call__(*arg, **kwarg)¶ Call self as a function.
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dict__= mappingproxy({'__module__': 'schrodinger.application.desmond.packages.timer', '__doc__': '\n You can use this class to create your own timer function with custom default\n behavior.\n\n Example usage:\n\n from schrodinger.application.desmond.packages.timer import Timer\n\n mytimer = Timer(threshold=0.2)\n # Creates a timer with 0.2 threshold.\n\n with mytimer("Reading the trajectory..."):\n traj.read_trj(trj_fname)\n\n In this example, `mytimer` behaves exactly the same as the standard\n `timer` (see the docstring of this module) except for the default value of\n `threshold` parameter that has been customed to 0.2.\n ', 'Args': <class 'schrodinger.application.desmond.packages.timer.Args'>, '__init__': <function Timer.__init__>, '__call__': <function Timer.__call__>, '__dict__': <attribute '__dict__' of 'Timer' objects>, '__weakref__': <attribute '__weakref__' of 'Timer' objects>})¶
-
__dir__() → list¶ default dir() implementation
-
__eq__¶ Return self==value.
-
__format__()¶ default object formatter
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__module__= 'schrodinger.application.desmond.packages.timer'¶
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ helper for pickle
-
__reduce_ex__()¶ helper for pickle
-
__repr__¶ Return repr(self).
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__() → int¶ size of object in memory, in bytes
-
__str__¶ Return str(self).
-
__subclasshook__()¶ Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
-
__weakref__¶ list of weak references to the object (if defined)