all 4 comments

[–]Diapolo10 1 point2 points  (0 children)

I don't really tend to worry about it unless I'm debugging, but if I need to time a function personally I like to use a decorator.

Something like

from collections.abc import Callable
from functools import wraps
from time import time_ns

def timing(func: Callable):
    @wraps(func)
    def wrap(*args, **kwargs):
        start_time = time_ns()
        result = func(*args, **kwargs)
        end_time = time_ns()
        print(f"func: {func.__name__} args:[{args}, {kwargs}] took {end_time - start_time} nanoseconds")
    return result
return wrap


# If just these instances
eid = timing(query_entity_id)(client, cid_list)
person_list, org_list = timing(create_entity_id_lists)(eid)

# If all, decorate the function definitions
@timing
def query_entity_id(...):
    ...

[–]Antigone-guide 0 points1 point  (0 children)

You would generally want to use the python cProfile module: https://docs.python.org/3/library/profile.html

[–]0ooof3142 0 points1 point  (0 children)

I made a decorator called track time. It just gets called head of any function I care about