October 19, 2024

Reducing the processing time of tasks processed on a program is a surprisingly difficult task. This is because programs run on the OS, and the OS is not solely dedicated to processing that program. Therefore, it is recommended to statistically measure how much time it takes. There is a library called timeit that is useful for measuring the processing time of such programs in Python, so I will explain how to use it.

import timeit

# function that you would like to measure processing time
def myfunc(model, images):

    with torch.no_grad():
        model(images)

stopwatch = timeit.Timer(
    functools.partial(myfunc, _model, _images)
)

#
print(stopwatch.timeit(10))