forked from tailhook/sortedsets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perftest.py
31 lines (27 loc) · 922 Bytes
/
perftest.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
import resource
from time import clock
from sortedsets import SortedSet
def test(size):
tm = clock()
ss = SortedSet((str(i), i*10) for i in range(size))
create_time = clock() - tm
print("SORTED SET WITH", size, "ELEMENTS", ss._level, "LEVELS")
print("Memory usage", resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
print("Creation time ", format(create_time, '10.2f'), "s")
num = 1000
step = size // (num + 2)
items = []
for i in range(step, size-step, step):
items.append((str(i), i*10))
tm = clock()
for k, v in items:
del ss[k]
del_time = num/(clock() - tm)
tm = clock()
for k, v in items:
ss[k] = v
ins_time = num/(clock() - tm)
print("Insertion speed", format(ins_time, '10.2f'), "ins/s")
print("Deletion speed ", format(del_time, '10.2f'), "del/s")
for size in (10000, 100000, 1000000, 10000000):
test(size)