summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xtest/all_benchmarks.py75
1 files changed, 35 insertions, 40 deletions
diff --git a/test/all_benchmarks.py b/test/all_benchmarks.py
index 84d6817d..e1b47142 100755
--- a/test/all_benchmarks.py
+++ b/test/all_benchmarks.py
@@ -14,45 +14,40 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-"""Run all the tests inside the test/ directory as a test suite."""
+"""
+Run all the benchmarks inside this directory.
+Usage: ./all_benchmarks.py [count] [regexp-filters...]
+"""
+
+import os
+import re
+import sys
+import time
+
 if __name__ == '__main__':
-	from re import compile
-	from test import *
-	from time import time
-	from types import FunctionType as function
-	from sys import argv
-	bms = []
-	try:
-		n = int(argv[1])
-	except IndexError:
-		n = 10
-	if len(argv) > 2:
-		args = [compile(re) for re in argv[2:]]
-		def allow(name):
-			for re in args:
-				if re.search(name):
-					return True
+	count   = int(sys.argv[1]) if len(sys.argv) > 1 else 10
+	regexes = [re.compile(fltr) for fltr in sys.argv[2:]]
+	modules = (fname[:-3] for fname in os.listdir(sys.path[0]) \
+			if fname[:3] == 'bm_' and fname[-3:] == '.py')
+
+	benchmarks = []  # find all benchmark (class, methodname) pairs
+	for val in [__import__(module) for module in modules]:
+		for cls in vars(val).values():
+			if type(cls) == type:
+				for methodname in vars(cls):
+					if methodname.startswith('bm_'):
+						benchmarks.append((cls, methodname))
+
+	for cls, methodname in benchmarks:
+		full_method_name = "{0}.{1}".format(cls.__name__, methodname)
+		if all(re.search(full_method_name) for re in regexes):
+			method = getattr(cls(), methodname)
+			t1 = time.time()
+			try:
+				method(count)
+			except:
+				print("{0} failed!".format(full_method_name))
+				raise
 			else:
-				return False
-	else:
-		allow = lambda name: True
-	for key, val in vars().copy().items():
-		if key.startswith('bm_'):
-			bms.extend(v for k,v in vars(val).items() if type(v) == type)
-	for bmclass in bms:
-		for attrname in vars(bmclass):
-			if not attrname.startswith('bm_'):
-				continue
-			bmobj = bmclass()
-			t1 = time()
-			method = getattr(bmobj, attrname)
-			methodname = "{0}.{1}".format(bmobj.__class__.__name__, method.__name__)
-			if allow(methodname):
-				try:
-					method(n)
-				except:
-					print("{0} failed!".format(methodname))
-					raise
-				else:
-					t2 = time()
-					print("{0:60}: {1:10}s".format(methodname, t2 - t1))
+				t2 = time.time()
+				print("{0:60}: {1:10}s".format(full_method_name, t2 - t1))
019array?h=hlt&id=fe67d47aa4598497e295510cf27f702a3e118632'>^
7b085072 ^

5497090a ^





7b085072 ^
7b085072 ^




7e9c6925 ^
ac0e9db5 ^


0487a30e ^
ac0e9db5 ^
7e9c6925 ^
827898fc ^
3076bab4 ^
a55bbd06 ^
7284d503 ^

88be3dbc ^
7e9c6925 ^
5497090a ^



afa42503 ^
7e9c6925 ^
7e9c6925 ^

88be3dbc ^
07d35c4a ^
5497090a ^




afa42503 ^
07d35c4a ^
07d35c4a ^

1848b18f ^

a55bbd06 ^

a55bbd06 ^

07d35c4a ^
0487a30e ^
7feea75b ^
ac0e9db5 ^
0487a30e ^

7feea75b ^
fca0ebbe ^
7e9c6925 ^
7feea75b ^

ac0e9db5 ^
7feea75b ^
d0de5837 ^
e853b94e ^
827898fc ^
7e9c6925 ^
0487a30e ^
a55bbd06 ^


7e9c6925 ^




88be3dbc ^
a55bbd06 ^
5497090a ^



afa42503 ^
a55bbd06 ^
7e9c6925 ^
a55bbd06 ^
7284d503 ^
1848b18f ^
88be3dbc ^
1848b18f ^
5497090a ^





1848b18f ^
1848b18f ^
1848b18f ^


a55bbd06 ^

a55bbd06 ^

0487a30e ^
ac0e9db5 ^
0487a30e ^
827898fc ^
fca0ebbe ^
7e9c6925 ^
ac0e9db5 ^
0487a30e ^
827898fc ^
a55bbd06 ^

c8a58cdc ^








afa42503 ^
c8a58cdc ^

















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