-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcomparision.py
40 lines (32 loc) · 1023 Bytes
/
comparision.py
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
29
30
31
32
33
34
35
36
37
38
39
40
from BSTSet import BSTSet
from Trie import Trie
if __name__ == '__main__':
words = ''
with open('./shakespeare.txt', 'r') as f:
words = f.read()
words = words.split()
from time import time
print("BST-SET")
start_time = time()
bst_set = BSTSet()
for word in words:
bst_set.add(word)
for word in words:
bst_set.contains(word)
print('Total words: ', len(words))
print('Unique words: ', bst_set.get_size())
print('Contains word "they": ', bst_set.contains('they'))
## 耗时0.58秒左右
print('Total time: {} seconds'.format(time() - start_time))
print("Trie")
start_time = time()
trie = Trie()
for word in words:
trie.add(word)
for word in words:
trie.contains(word)
print('Total words: ', len(words))
print('Unique words: ', trie.get_size())
print('Contains word "they": ', trie.contains('they'))
## 耗时0.58秒左右
print('Total time: {} seconds'.format(time() - start_time))