You can use timeit.
def function_to_test(n):
for i in range(n):
pass
import timeit
start = timeit.default_timer()
# Put the code to measure here
function_to_test(300000)
stop = timeit.default_timer()
print(stop - start)
You can do it like this. I don't know what's different from the top comment or what's good.
import time
startTime = time.time()
# Execution Code
endTime = time.time() - startTime
print(endTime)
© 2024 OneMinuteCode. All rights reserved.