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)

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)

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.