Skip to content

Commit c244dc1

Browse files
committed
updates
1 parent ffbb005 commit c244dc1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

06_execution_time.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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())

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions
66
3. **04_rename_with_slice.py**: rename group of files, within a single directory, using slice
77
4. **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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy