-
Notifications
You must be signed in to change notification settings - Fork 80
/
benchmarks.py
139 lines (108 loc) · 3.58 KB
/
benchmarks.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
from __future__ import unicode_literals
import random
try:
from sourmash._minhash import MinHash
except:
from sourmash.minhash import MinHash
def load_sequences():
sequences = []
for i in range(10):
random_seq = random.sample("A,C,G,T".split(",") * 3000, 300)
sequences.append("".join(random_seq))
return sequences
class TimeMinHashSuite:
def setup(self):
self.mh = MinHash(500, 21, track_abundance=False)
self.protein_mh = MinHash(500, 21, is_protein=True, track_abundance=False)
self.sequences = load_sequences()
self.populated_mh = MinHash(500, 21, track_abundance=False)
for seq in self.sequences:
self.populated_mh.add_sequence(seq)
def time_add_sequence(self):
mh = self.mh
sequences = self.sequences
for seq in sequences:
mh.add_sequence(seq)
def time_add_protein(self):
mh = self.protein_mh
sequences = self.sequences
for seq in sequences:
mh.add_protein(seq)
def time_get_mins(self):
mh = self.populated_mh
for i in range(500):
mh.get_mins()
def time_add_hash(self):
mh = self.mh
for i in range(10000):
mh.add_hash(i)
def time_add_many(self):
mh = self.mh
mh.add_many(list(range(1000)))
def time_compare(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(500):
mh.compare(other_mh)
def time_count_common(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(500):
mh.count_common(other_mh)
def time_merge(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(500):
mh.merge(other_mh)
def time_copy(self):
mh = self.populated_mh
for i in range(500):
mh.__copy__()
def time_concat(self):
mh = self.mh
other_mh = self.populated_mh
for i in range(500):
mh += other_mh
class PeakmemMinHashSuite:
def setup(self):
self.mh = MinHash(500, 21, track_abundance=True)
self.protein_mh = MinHash(500, 21, is_protein=True, track_abundance=True)
self.sequences = load_sequences()
def peakmem_add_sequence(self):
mh = self.mh
sequences = self.sequences
for seq in sequences:
mh.add_sequence(seq)
def peakmem_add_protein(self):
mh = self.protein_mh
sequences = self.sequences
for seq in sequences:
mh.add_protein(seq)
def peakmem_add_hash(self):
mh = self.mh
for i in range(10000):
mh.add_hash(i)
def peakmem_add_many(self):
mh = self.mh
mh.add_many(list(range(1000)))
####################
class TimeMinAbundanceSuite(TimeMinHashSuite):
def setup(self):
TimeMinHashSuite.setup(self)
self.mh = MinHash(500, 21, track_abundance=True)
self.populated_mh = MinHash(500, 21, track_abundance=True)
for seq in self.sequences:
self.populated_mh.add_sequence(seq)
def time_get_mins_abundance(self):
mh = self.populated_mh
for i in range(500):
mh.get_mins(with_abundance=True)
def time_set_abundances(self):
mh = self.mh
mins = self.populated_mh.get_mins(with_abundance=True)
for i in range(500):
mh.set_abundances(mins)
class PeakmemMinAbundanceSuite(PeakmemMinHashSuite):
def setup(self):
PeakmemMinHashSuite.setup(self)
self.mh = MinHash(500, 21, track_abundance=True)