schrodinger.utils.profiling module¶
Profiling and timing decorators.
For more information on profiling python code, see also https://internal.schrodinger.com/products/development/docs/software_engineering/profiling.html#profiling-python-code
A very simple example showing the use the profiling and timing decorators:
import time
@profiling
def profiled_function(duration=0.05):
time.sleep(duration)
@timing
def timed_function(duration=0.05):
time.sleep(duration)
class Test(object):
@profiling
def profiledMethod(self, duration=0.05):
time.sleep(duration)
@timing
def timedMethod(self, duration=0.05):
time.sleep(duration)
test = Test()
# call the profiled method
test.profiledMethod()
# call the timed method
test.timedMethod(0.1)
# call the profiled function
profiled_function()
# call the timed function
timed_function(0.1)
- schrodinger.utils.profiling.profiling(f, *args, **kwargs)[source]¶
Decorator that will generate a profile file with the name of the decorated function or method and time stamp. The duration of the execution of decorated function or method will also be printed to the terminal.
- schrodinger.utils.profiling.timing(f)[source]¶
Decorator that will print the duration of the execution of decorated function or method to the terminal every time it’s called. Will also report the average time, minimum time, and the total number of calls on program exit.
- schrodinger.utils.profiling.profile_call(func, *args, profile_filename=None, **kwargs)[source]¶
Profile the specified function call.
- Parameters
func (Callable) – The function to profile. All arguments to
profile_call
other thanprofile_filename
will be passed to this function.profile_filename (str) – The name of the file to save the profiling data to. Note that this argument is keyword-only and is required.
- Returns
The value returned by
func
.- Return type
object
- schrodinger.utils.profiling.profile(profile_filename='program.prof')[source]¶
Profile a block of code and dump the results into a file. Should be used as a context manager, e.g.,
- with profile(profile_filename=’mystats.prof’):
execute_some_code()
- Parameters
profile_filename (str) – The name of the file to save the profiling data to.
- Return type
cProfile.Profile
- Returns
The profiling object being used