forked from markfasheh/interval-tree
-
Notifications
You must be signed in to change notification settings - Fork 2
/
timings.py
103 lines (60 loc) · 2.38 KB
/
timings.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
from time import time
import datetime
from numpy.random import randint
import numpy as np
import pandas as pd
import intervaltree as it
import quicksect as qs
import kerneltree as kt
total_nb = int(1e6)
starts = randint(0, int(1e8), total_nb)
ends = starts + randint(1, 200, total_nb)
values = np.array(range(total_nb))
def test_build_it(starts, ends, values):
start = time()
it_it = it.IntervalTree()
for s, e, v in zip(starts, ends, values):
it_it[s:e] = v
end = time()
total = end - start
total_dt = datetime.datetime.fromtimestamp(total)
minutes, seconds = total_dt.strftime('%M\t%S\n').split()
print("Python based intervaltrees took", minutes, "minutes and", seconds, "seconds to build the tree.")
def test_build_qs(starts, ends, values):
start = time()
qs_it = qs.IntervalTree()
for s, e, v in zip(starts, ends, values):
qs_it.add(s, e, v)
end = time()
total = end - start
total_dt = datetime.datetime.fromtimestamp(total)
minutes, seconds = total_dt.strftime('%M\t%S\n').split()
print("Cython based intervaltrees took", minutes, "minutes and", seconds, "seconds to build the tree.")
def test_build_kt(starts, ends, values):
start = time()
kt_it = kt.IntervalTree()
for s, e, v in zip(starts, ends, values):
kt_it.add(s, e, v)
end = time()
total = end - start
total_dt = datetime.datetime.fromtimestamp(total)
minutes, seconds = total_dt.strftime('%M\t%S\n').split()
print("C based intervaltrees took", minutes, "minutes and", seconds, "seconds to build the tree.")
def test_build_kt_helper(starts, ends, values):
start = time()
kt_it = kt.IntervalTree()
kt_it.build(starts, ends, values)
end = time()
total = end - start
total_dt = datetime.datetime.fromtimestamp(total)
minutes, seconds = total_dt.strftime('%M\t%S\n').split()
print(kt_it.search(1, 2))
print("C based intervaltrees took", minutes, "minutes and", seconds, "seconds to build the tree using the helper function build.")
print("Starting to build.")
test_build_kt_helper(starts, ends, values)
# test_build_it(list(starts), list(ends), list(values))
# test_build_qs(list(starts), list(ends), list(values))
# starts, ends, values = list(starts), list(ends), list(values)
# test_build_kt(starts, ends, values)
# it_qs = qs.IntervalTree()
# it_kt = kt.IntervalTree()