Skip to content

Commit 4de6a76

Browse files
Determenistic function
1 parent da6ba80 commit 4de6a76

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

determenistic/__init__.py

Whitespace-only changes.

determenistic/determtic.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import collections
2+
import functools
3+
import time
4+
5+
6+
@functools.lru_cache(maxsize=200)
7+
def count_words(sentence):
8+
_count = collections.Counter()
9+
for w in str(sentence).split():
10+
_count[w] += 1
11+
return _count
12+
13+
14+
if __name__ == "__main__":
15+
16+
sen = """In mathematics, computer science and physics,
17+
a deterministic system is a system in which no
18+
randomness is involved in the development of future states of the system"""
19+
20+
for i in range(3):
21+
start_time = time.perf_counter()
22+
count = count_words(sen)
23+
stop_time = time.perf_counter()
24+
print("Exec #{} time: {:.9f}".format(i, stop_time-start_time))

0 commit comments

Comments
 (0)