nutsman
0
Q:

how to time python code

import time

t0 = time.time()
code_block
t1 = time.time()

total = t1-t0
7
import time

start = time.time()
print("hello")
end = time.time()
print(end - start)
8
import timeit
import_module = "import random"
testcode = ''' 
def test(): 
    return random.randint(10, 100)
'''
print(timeit.repeat(stmt=testcode, setup=import_module))
6
import time
timer_length = float(input("How many seconds would you like you're timer to be set for? "))
time.sleep(timer_length)
print("Done!")
3
from timer import Timer
t = Timer()
t.start()
# Run stuff here.
t.stop()  
0

New to Communities?

Join the community