8000 Add files via upload · Brivno1234/python-scripts@0c56bb1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c56bb1

Browse files
authored
Add files via upload
1 parent cb448c2 commit 0c56bb1

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

scripts/06_execution_time.py

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
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-
import random
17-
18-
19-
class ExecutionTime:
20-
def __init__(self):
21-
self.start_time = time.time()
22-
23-
def duration(self):
24-
return time.time() - self.start_time
25-
26-
27-
# ---- run code ---- #
28-
29-
30-
timer = ExecutionTime()
31-
sample_list = list()
32-
my_list = [random.randint(1, 888898) for num in
33-
range(1, 1000000) if num % 2 == 0]
34-
print('Finished in {} seconds.'.format(timer.duration()))
1+
import time
2+
import random
3+
4+
5+
class ExecutionTime:
6+
def __init__(self):
7+
self.start_time = time.time()
8+
9+
def duration(self):
10+
return time.time() - self.start_time
11+
12+
13+
timer = ExecutionTime()
14+
sample_list = []
15+
16+
for i in range (1,1000000):
17+
if i % 2 == 0:
18+
sample_list.append(random.randint(1,888888))
19+
20+
for i in range(10):
21+
print(11111)
22+
23+
print("finished in {}seconds.".format(timer.duration()))

0 commit comments

Comments
 (0)
0