File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ ExecutionTime
3+
4+ This class is used for timing execution of code.
5+
6+ For example:
7+
8+ timer = ExecutionTime()
9+ print 'Hello world!'
10+ print 'Finished in{} seconds.'.format(timer.duration())
11+
12+ """
13+
14+
15+ import time
16+
17+
18+ class ExecutionTime :
19+ def __init__ (self ):
20+ self .start_time = time .time ()
21+
22+ def duration (self ):
23+ return time .time () - self .start_time
24+
25+
26+ # ---- run code ---- #
27+
28+ import random
29+
30+ timer = ExecutionTime ()
31+ sample_list = list ()
32+ my_list = [random .randint (1 , 888898 ) for num in xrange (1 , 1000000 ) if num % 2 == 0 ]
33+ print 'Finished in{} seconds.' .format (timer .duration ())
Original file line number Diff line number Diff line change 551 . ** 03_simple_twitter_manager.py** : accessing the Twitter API, example functions
663 . ** 04_rename_with_slice.py** : rename group of files, within a single directory, using slice
774 . ** 05_load_json_without_dupes.py** : load json, convert to dict, raise error if there is a duplicate key
8+ 5 . ** 06_execution_time.py** : class used for timing execution of code
You can’t perform that action at this time.
0 commit comments