1import time
2
3start = time.time()
4print("hello")
5end = time.time()
6print(end - start)
1import datetime
2
3currentDT = datetime.datetime.now()
4print(str(currentDT))
5
6# prints XXXX-XX-XX XX:XX:XX.XXXXXX
7# or
8
9import datetime
10
11currentDT = datetime.datetime.now()
12
13print ("Current Year is: %d" % currentDT.year)
14print ("Current Month is: %d" % currentDT.month)
15print ("Current Day is: %d" % currentDT.day)
16print ("Current Hour is: %d" % currentDT.hour)
17print ("Current Minute is: %d" % currentDT.minute)
18print ("Current Second is: %d" % currentDT.second)
19print ("Current Microsecond is: %d" % currentDT.microsecond)
20# prints
21"""
22Current Year is: XXXX
23Current Month is: XX
24Current Day is: XX
25Current Hour is: XX
26Current Minute is: XX
27Current Second is: XX
28Current Microsecond is: XXXXXX
29"""
1import time
2start = time.process_time()
3# your code here
4print(time.process_time() - start)
1import time
2
3start = time.time()
4print("hello")
5end = time.time()
6print(end - start)
7
1import time
2t0= time.clock()
3print("Hello")
4t1 = time.clock() - t0
5print("Time elapsed: ", t1) # CPU seconds elapsed (floating point)
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