This commit is contained in:
Michael Herman 2014-05-05 02:40:08 -05:00
parent ffbb005359
commit c244dc161d
2 changed files with 34 additions and 0 deletions

33
06_execution_time.py Normal file
View File

@ -0,0 +1,33 @@
"""
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
class ExecutionTime:
def __init__(self):
self.start_time = time.time()
def duration(self):
return time.time() - self.start_time
# ---- run code ---- #
import random
timer = ExecutionTime()
sample_list = list()
my_list = [random.randint(1, 888898) for num in xrange(1, 1000000) if num % 2 == 0]
print 'Finished in {} seconds.'.format(timer.duration())

View File

@ -5,3 +5,4 @@
1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions 1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions
3. **04_rename_with_slice.py**: rename group of files, within a single directory, using slice 3. **04_rename_with_slice.py**: rename group of files, within a single directory, using slice
4. **05_load_json_without_dupes.py**: load json, convert to dict, raise error if there is a duplicate key 4. **05_load_json_without_dupes.py**: load json, convert to dict, raise error if there is a duplicate key
5. **06_execution_time.py**: class used for timing execution of code