-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetermtic.py
More file actions
28 lines (21 loc) · 794 Bytes
/
determtic.py
File metadata and controls
28 lines (21 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import collections
import functools
import time
@functools.lru_cache(maxsize=200)
def count_words(sentence):
_count = collections.Counter()
for w in str(sentence).split():
_count[w] += 1
return _count
if __name__ == "__main__":
sen = """In mathematics, computer science and physics,
a deterministic system is a system in which no
randomness is involved in the development of future states of the system"""
times = []
for i in range(3):
start_time = time.perf_counter()
count = count_words(sen)
stop_time = time.perf_counter()
time_taken = stop_time-start_time
times.append(time_taken)
print("Exec #{} time: {:.9f} performance gain {:%}".format(i, time_taken, 1-times[i]/times[0]))