Aggregate Code timing in Python
Group by the code timings in Python using codetiming library. There are many ways to get how much time a function takes in Python. Here is an easy decorator implementation to check how much time a function takes. This decorator can be used by decorating a function to get the time spent. What if you want to aggregate this timing data in a timeframe, like how many times this function has been called, and what the maximum time is taken, for that, we need to use a library called codetiming. Here is a sample use case: This will find the aggregated time spent by At the end Do you want to use an in-memory LRU cache with a timeout, you may check out this article: I post on Python programming on my Twitter handle, you can follow me @soumendrak_. Aggregate Code timing in Python
=
=
=
= -
return
return
# do stuff
# pip install codetiming
# pip install humanfriendly
# pip install loguru
...
=
# clears all the timer data
my_func
. Let’s go through what each one of them will log:Timer.timers.clear()
clears the data stored In memory and starts from fresh for the next iteration.