forked from boostorg/compute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf.py
executable file
·194 lines (153 loc) · 4.61 KB
/
perf.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/python
# driver script for boost.compute benchmarking. will run a
# benchmark for a given function (e.g. accumulate, sort).
import os
import sys
import random
import subprocess
try:
import pylab
except:
print 'pylab not found, no ploting...'
pass
def run_perf_process(name, size, backend = ""):
if not backend:
proc = "perf_%s" % name
else:
proc = "perf_%s_%s" % (backend, name)
try:
output = subprocess.check_output(["./perf/" + proc, str(int(size))])
except:
return 0
t = 0
for line in output.split("\n"):
if line.startswith("time:"):
t = float(line.split(":")[1].split()[0])
return t
class Report:
def __init__(self, name):
self.name = name
self.samples = {}
def add_sample(self, name, size, time):
if not name in self.samples:
self.samples[name] = []
self.samples[name].append((size, time))
def display(self):
for name in self.samples.keys():
print '=== %s with %s ===' % (self.name, name)
print 'size,time (ms)'
for sample in self.samples[name]:
print '%d,%f' % sample
def plot_time(self, name):
if not name in self.samples:
return
x = []
y = []
any_valid_samples = False
for sample in self.samples[name]:
if sample[1] == 0:
continue
x.append(sample[0])
y.append(sample[1])
any_valid_samples = True
if not any_valid_samples:
return
pylab.plot(x, y, marker='o', label=name)
pylab.xlabel("Size")
pylab.ylabel("Time (ms)")
pylab.title(self.name)
def plot_rate(self, name):
if not name in self.samples:
return
x = []
y = []
any_valid_samples = False
for sample in self.samples[name]:
if sample[1] == 0:
continue
x.append(sample[0])
y.append(float(sample[0]) / (float(sample[1]) * 1e-3))
any_valid_samples = True
if not any_valid_samples:
return
pylab.plot(x, y, marker='o', label=name)
pylab.xlabel("Size")
pylab.ylabel("Rate (values/s)")
pylab.title(self.name)
def run_benchmark(name, sizes, vs=[]):
report = Report(name)
for size in sizes:
time = run_perf_process(name, size)
report.add_sample("compute", size, time)
competitors = {
"thrust" : ["accumulate",
"count",
"inner_product",
"partial_sum",
"sort",
"saxpy"],
"tbb": ["accumulate",
"merge",
"sort"],
"stl": ["accumulate",
"count",
"find_end",
"includes",
"inner_product",
"is_permutation",
"merge",
"next_permutation",
"partial_sum",
"partition",
"partition_point",
"prev_permutation",
"reverse",
"rotate",
"rotate_copy",
"search",
"search_n",
"set_difference",
"set_intersection",
"set_symmetric_difference",
"set_union",
"sort",
"stable_partition",
"unique",
"unique_copy"]
}
for other in vs:
if not other in competitors:
continue
if not name in competitors[other]:
continue
for size in sizes:
time = run_perf_process(name, size, other)
report.add_sample(other, size, time)
return report
if __name__ == '__main__':
test = "sort"
if len(sys.argv) >= 2:
test = sys.argv[1]
print 'running %s perf test' % test
sizes = [ pow(2, x) for x in range(1, 26) ]
sizes = sorted(sizes)
competitors = ["tbb", "thrust", "stl"]
report = run_benchmark(test, sizes, competitors)
plot = None
if "--plot-time" in sys.argv:
plot = "time"
elif "--plot-rate" in sys.argv:
plot = "rate"
if plot == "time":
report.plot_time("compute")
for competitor in competitors:
report.plot_time(competitor)
elif plot == "rate":
report.plot_rate("compute")
for competitor in competitors:
report.plot_rate(competitor)
if plot:
pylab.legend()
pylab.show()
else:
report.display()