+ 2

How to print the time of execution of functions inside the code ?

I'm writting a code with at least 3 defined functions. At the end, I want to print the eficiency of each functinon. def function_1 (): ... def function_2 (): ... def function_3 (): ... time of execution function_1 (): 0.0054 mileseconds time of execution function_2 ():0.0233 mileseconds time of execution function_3 ():0.0478 mileseconds How can I do this ?

18th May 2018, 5:01 PM
▲TopGun ▲
▲TopGun ▲ - avatar
2 ответов
+ 1
Paste this in the end of each function, so you will get timestamp after function execution import time import datetime ts = time.time() // <--- this print ts // <--- this // or st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') // <--- this print st // <--- this
18th May 2018, 5:08 PM
BugBuster
BugBuster - avatar
+ 1
I'm not sure how deep you want to get with performance. I found this blog to be very helpful. https://www.ploggingdev.com/2016/12/performance-measurement-in-JUMP_LINK__&&__python__&&__JUMP_LINK-3/
18th May 2018, 5:32 PM
ODLNT
ODLNT - avatar