-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
50 lines (38 loc) · 986 Bytes
/
benchmark.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
from random import randint, seed
from skip_list import SkipList
# from rbTree import rbtree
from linked_list import LinkedList
from time import clock
def randomSequence(n):
seed(0)
i = 0
while i < n:
yield randint(1, n)
i += 1
def increasingSequence(n):
i = 0
while i < n:
yield i
i += 1
def decreasingSequence(n):
i = n-1
while i >= 0:
yield i
i -= 1
def insertions(structure, generator):
for s in generator:
structure.insert(s)
def benchmarkOperation(structure, op, seq):
start = clock()
op(structure, seq)
return (clock() - start)
def benchmark(generator):
seq = list(generator)
sl = SkipList()
slt = benchmarkOperation(sl, insertions, seq)
l = LinkedList()
lt = benchmarkOperation(l, insertions, seq)
print '%.2lf & %.2lf\\\\' % (slt, lt)
benchmark(randomSequence(10000))
benchmark(increasingSequence(10000))
benchmark(decreasingSequence(10000))