import time
start = time.time()
print("hello")
end = time.time()
print(end - start)
import time
start_time = time.time()
# code
print("--- %s seconds ---" % (time.time() - start_time))
#!/usr/bin/python
import time
t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
t = time.mktime(t)
print time.strftime("%b %d %Y %H:%M:%S", time.gmtime(t))
OUTPUT:Feb 18 2009 00:03:38
#import time module:
import time
#module has various attributes:
dir(time)
[..., 'localtime', 'mktime', 'sleep', 'sleep_ms', 'sleep_us', 'ticks_add', 'ticks_cpu', 'ticks_diff', 'ticks_ms', 'ticks_us', 'time']
#default expression is in seconds with zero being start of runtime
secFromStart = time.time()
import time
thistime = time.time()
# Here's an idea!
def CountTime():
while(True):
time.sleep(1)
print(thistime)
CountTime()
Proper answer to timing a loop over a function multiple times
import timeit
timeit.timeit('func_to_time()',globals=globals(),number=1000)