Python: Measure Runtime

Just a short post on finding the execution time of a given code in Python. Here’s how to do it:

import time
 
start = time.time()
x = demoFunctionSum(x,y) # measuring the exec time of this code
end = time.time()
 
total = end-start
total = int(round(total*1000*1000)) # 10^6 is micro-seconds
print(total)

That’s all.

Just replace demoFunctionSum() with your function call πŸ™‚