1import time
2
3start = time.time()
4print("hello")
5end = time.time()
6print(end - start)
1import time
2
3start = time.time()
4print("hello")
5end = time.time()
6print(end - start)
7
1import time
2
3# Calculate the power of two for a defined range of number
4def power_two(my_range):
5 return [x**2 for x in range(my_range)]
6
7# Measure time
8def measure_time(func):
9 start = time.time()
10 func() # any specific function to measure
11 end = time.time()
12 print(end - start)
13
14measure_time(lambda: power_two(10000000)) # lambda permits to pass the argument of our function
1import timeit
2import_module = "import random"
3testcode = '''
4def test():
5 return random.randint(10, 100)
6'''
7print(timeit.repeat(stmt=testcode, setup=import_module))
8
1import time
2timer_length = float(input("How many seconds would you like you're timer to be set for? "))
3time.sleep(timer_length)
4print("Done!")