Time Python Code Like a PRO with THIS Snippet

preview_player
Показать описание
Time Python code like a pro with this snippet. #python #code #shorts
Рекомендации по теме
Комментарии
Автор

really amazing to know, I had once created a complex decorator function to get time taken by different processes and print the time report a dict at the end.

paljain
Автор

I'm not there yet but this will be useful for me soon I imagine, thank you for this. You've got a lot of videos that have been very informative for me as I'm learning Python, but could you by chance label your shorts somehow so they're easier to reference?

Rage
Автор

Why not just do

time_before=time.time()
...
time_after = time.time()
time_taken = time_after - time_before

zyxwv
Автор

I'm curious - why use a context manager instead of a decorator wrapper? Make a decorator function that just wraps around the original one and gets the start time before the decorated function is run, end time after the function completes, and return both the function's return value and the (end - start) time?

hunterap
Автор

Do we have to change the contextmanager decorator for the case of cogs?

midascostly
Автор

Why not import logging so that we can see the logger as well

Ron-ojgm
Автор

why not use the in-built timeit package?

Jugularst
Автор

Or... get time.perf at the start and the end and subtract them? Never got this kind of complication.

mazarinee
Автор

im a senior dev and i just count myself

andreas-vh
Автор

How is this more useful than writing a decorator?

kaskilelr