-
Notifications
You must be signed in to change notification settings - Fork 2
/
performance.py
189 lines (176 loc) · 5.01 KB
/
performance.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import time
from timeit import default_timer as timer
from disklist import DiskList
def main():
"""
Compare disklists and lists
"""
# Instantiation
print('|---------- Instanciation ----------|')
# List
start = timer()
for _ in range(0, 1000):
l = []
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for _ in range(0, 1000):
dl = DiskList()
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Instantiation with big object
print('|---------- Instanciation with big object ----------|')
# List
start = timer()
for _ in range(0, 1000):
lbo = []
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for _ in range(0, 1000):
dlbo = DiskList()
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Append
print('|---------- Appending ----------|')
# List
start = timer()
for i in range(0, 1000):
l.append(i)
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for i in range(0, 1000):
dl.append(i)
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Append big object
print('|---------- Appending big object ----------|')
# List
big_obj = ["test" for _ in range(0, 1000)]
start = timer()
for i in range(0, 1000):
lbo.append(big_obj)
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for i in range(0, 1000):
dlbo.append(big_obj)
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Inserting
print('|---------- Inserting ----------|')
# List
start = timer()
for i in range(0, 1000):
l.insert(i, i)
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for i in range(0, 1000):
dl.insert(i, i)
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Inserting big object
print('|---------- Inserting big object ----------|')
# List
big_obj = ["test" for _ in range(0, 1000)]
start = timer()
for i in range(0, 1000):
lbo.insert(i, big_obj)
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for i in range(0, 1000):
dlbo.insert(i, big_obj)
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Getting with index
print('|------ Getting with index ------|')
# List
start = timer()
for i in range(0, 1000):
l[i]
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for _ in range(0, 1000):
dl[i]
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Setting with index
print('|------ Setting with index ------|')
# List
start = timer()
for i in range(0, 1000):
l[i] = i
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for _ in range(0, 1000):
dl[i] = i
end = timer()
print('DiskList: {:.10f} sec'.format((end - start) / 1000))
# Iterating
print('|---------- Iterating ----------|')
# List
start = timer()
for i in range(0, 1000):
for item in l:
continue
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for _ in range(0, 1000):
for item in dl:
continue
end = timer()
print('DiskList without cache: {:.10f} sec'.format((end - start) / 1000))
# DiskList
dl = DiskList(cache_size=256) # 256 items
for i in range(0, 1000):
dl.append(i)
start = timer()
for _ in range(0, 1000):
for item in dl:
continue
end = timer()
print('DiskList with cache: {:.10f} sec'.format((end - start) / 1000))
# Iterating with big object
print('|---------- Iterating with big object ----------|')
# List
start = timer()
for i in range(0, 1000):
for item in lbo:
continue
end = timer()
print('List: {:.10f} sec'.format((end - start) / 1000))
# DiskList
start = timer()
for _ in range(0, 1000):
for item in dlbo:
continue
end = timer()
print('DiskList without cache: {:.10f} sec'.format((end - start) / 1000))
# DiskList
dlbo = DiskList(cache_size=256) # 256 items
big_obj = ["test" for _ in range(0, 1000)]
for i in range(0, 1000):
dlbo.append(big_obj)
start = timer()
for _ in range(0, 1000):
for item in dlbo:
continue
end = timer()
print('DiskList with cache: {:.10f} sec'.format((end - start) / 1000))
if __name__=='__main__':
main()