2014-05-05 09:40:08 +02:00
|
|
|
"""
|
|
|
|
ExecutionTime
|
|
|
|
|
|
|
|
This class is used for timing execution of code.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
timer = ExecutionTime()
|
|
|
|
print 'Hello world!'
|
|
|
|
print 'Finished in {} seconds.'.format(timer.duration())
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import time
|
2015-05-17 11:49:35 +02:00
|
|
|
import random
|
2014-05-05 09:40:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ExecutionTime:
|
|
|
|
def __init__(self):
|
|
|
|
self.start_time = time.time()
|
|
|
|
|
|
|
|
def duration(self):
|
|
|
|
return time.time() - self.start_time
|
|
|
|
|
|
|
|
|
|
|
|
# ---- run code ---- #
|
|
|
|
|
|
|
|
|
|
|
|
timer = ExecutionTime()
|
|
|
|
sample_list = list()
|
2015-05-17 11:49:35 +02:00
|
|
|
my_list = [random.randint(1, 888898) for num in
|
|
|
|
range(1, 1000000) if num % 2 == 0]
|
|
|
|
print('Finished in {} seconds.'.format(timer.duration()))
|