-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport-shootout
executable file
·330 lines (259 loc) · 8.62 KB
/
report-shootout
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/python
import json
import sys
import re
import copy
import os
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def displayTag(t):
return t
def json_careful_loads(s):
try:
return json.loads(s)
except Exception as e:
sys.stderr.write("[ERR] Error while parsing json: {}\n".format(e))
sys.exit(1)
def json_careful_readlines(f):
return [ json_careful_loads(line.rstrip('\n')) for line in f ]
def safeInsert(dict, key, value):
if key not in dict:
dict[key] = value
else:
sys.stderr.write("[WARN] Key {} is already in use; trying _{} instead.\n".format(key))
safeInsert(dict, "_" + key, value)
def reCompile(exp):
return re.compile(exp, re.MULTILINE)
def parseKiB(kibStr):
return int(kibStr) * 1024.0 / 1000.0
def parseB(bytesStr):
return int(bytesStr) / 1000.0
def getWallTimes(row):
lines = row['stdout'].split("\n")
tms = []
for line in lines:
m = re.search(r"^wall\s+(\d+)$", line)
if m:
seconds = float(m.group(1)) / 1000.0
tms.append(seconds)
return tms
statsPatterns = \
[ ("time", float, reCompile(r"^end-to-end\s+(\d+.\d+)s$"))
, ("space", parseKiB, reCompile(r"^\s*Maximum resident set size \(kbytes\): (\d+).*$"))
]
foundTags = set()
foundProcs = set()
def parseStats(row):
newRow = copy.deepcopy(row)
for (name, convert, pat) in statsPatterns:
m = pat.search(newRow['stdout'] + newRow['stderr'])
if m:
safeInsert(newRow, name, convert(m.group(1)))
newRow['procs'] = int(newRow.get('procs', '1'))
# newRow['config'] = row['config']
try:
newRow['space'] = float(newRow['space'])
except KeyError:
pass
# try:
# newRow['time'] = float(newRow['elapsed'])
# except KeyError:
# pass
foundTags.add(newRow['tag'])
foundProcs.add(newRow['procs'])
return newRow
def findTrials(data, config, tag, procs):
result = []
for row in data:
if (row['config'] == config and \
row['tag'] == tag and \
row['procs'] == procs):
result.append(row)
return result
def getTimes(data, config, tag, procs):
for row in data:
if (row['config'] == config and \
row['tag'] == tag and \
row['procs'] == procs):
return getWallTimes(row)
return None
def getSpace(data, config, tag, procs):
for row in data:
if (row['config'] == config and \
row['tag'] == tag and \
row['procs'] == procs):
return row['space']
return None
def averageTime(data, config, tag, procs):
tms = [ r['time'] for r in findTrials(data, config, tag, procs) if 'time' in r ]
# cut out the max time to account for possible file IO slowdown
# (this should only happen the first time the file is loaded)
# if len(tms) > 1:
# maxt = max(tms)
# tms = [ t for t in tms if t != maxt ]
# take last ten runs
if len(tms) > 10:
tms = tms[-10:]
try:
return sum(tms) / len(tms)
except:
return None
def averageSpace(data, config, tag, procs):
sp = [ r['space'] for r in findTrials(data, config, tag, procs) if 'space' in r ]
if len(sp) > 10:
sp = sp[-10:]
try:
return sum(sp) / len(sp)
except:
return None
def renameConfig(c):
if c == 'mlton':
return 'MLton'
elif c == 'mpl':
return 'MPL'
elif c == 'mpl-cc':
return 'MPL* (Ours)'
elif c == 'java':
return 'Java'
elif c == 'go':
return 'Go'
return '??'
# ===========================================================================
def mostRecentResultsFile():
files = os.listdir("results")
pattern = r'sort-\d{6}-\d{6}'
# A bit of a hack. Filenames are ...YYMMDD-hhmmss, so lexicographic string
# comparison is correct for finding the most recent (i.e. maximum) file
mostRecent = max(p for p in files if re.match(pattern, p))
return mostRecent
if len(sys.argv) > 1:
resultsFile = sys.argv[1]
else:
print("[INFO] no results file argument; finding most recent")
try:
mostRecent = mostRecentResultsFile()
except:
print("[ERR] could not find most recent results file\n " + \
" check that these are formatted as 'YYMMSS-hhmmss'")
sys.exit(1)
resultsFile = os.path.join('results', mostRecent)
print("[INFO] reading {}\n".format(resultsFile))
with open(resultsFile, 'r') as data:
resultsData = json_careful_readlines(data)
D = [ parseStats(row) for row in resultsData ]
# ===========================================================================
# remove first 5 runs, call it warmup
# warmupRuns = 5
# def averageAfterWarmup(config, procs):
# tms = getTimes(D, config, 'sort-shootout', procs)
# try:
# tms = tms[warmupRuns:]
# return sum(tms) / len(tms)
# except:
# return None
def averageAfterWarmup(config, procs):
return averageTime(D, config, 'sort-shootout', procs)
# def maxRes(config, procs):
# sp = getSpace(D, config, 'sort-shootout', procs)
# try:
# return sp / 1000.0 / 1000.0 # GB
# except:
# return None
def maxRes(config, procs):
try:
return averageSpace(D, config, 'sort-shootout', procs) / 1000.0 / 1000.0
except:
return None
# print("==== TIMES ====")
# print("MLTON 1 " + str(averageAfterWarmup('mlton', 1)))
# print("MPL 1 " + str(averageAfterWarmup('mpl', 1)))
# print("MPL 72 " + str(averageAfterWarmup('mpl', 72)))
# print("MPL/CC 1 " + str(averageAfterWarmup('mpl-cc', 1)))
# print("MPL/CC 72 " + str(averageAfterWarmup('mpl-cc', 72)))
# print("JAVA 1 " + str(averageAfterWarmup('java', 1)))
# print("JAVA 72 " + str(averageAfterWarmup('java', 72)))
# print("GO 1 " + str(averageAfterWarmup('go', 1)))
# print("GO 72 " + str(averageAfterWarmup('go', 72)))
# print("")
# print("==== SPACE ====")
# print("MLTON 1 " + str(maxRes('mlton', 1)))
# print("MPL 1 " + str(maxRes('mpl', 1)))
# print("MPL 72 " + str(maxRes('mpl', 72)))
# print("MPL/CC 1 " + str(maxRes('mpl-cc', 1)))
# print("MPL/CC 72 " + str(maxRes('mpl-cc', 72)))
# print("JAVA 1 " + str(maxRes('java', 1)))
# print("JAVA 72 " + str(maxRes('java', 72)))
# print("GO 1 " + str(maxRes('go', 1)))
# print("GO 72 " + str(maxRes('go', 72)))
# print("")
# ==========================================================================
configs = ['mpl-cc', 'java', 'go']
colors = ['blue', 'green', 'red', 'darkturquoise', 'black', 'darkviolet', 'goldenrod', 'dimgrey']
markers = ['o','v','^','<','>','s','d','D']
linestyles = ['solid', 'dashed']
procs = [1,10,20,30,40,50,60,70]
plt.figure(figsize=(6,6))
fontSize = 18
legendFontSize = 14
markerSize = 8
baseline = min([averageAfterWarmup(c, 1) for c in configs])
# baseline = averageAfterWarmup('mlton', 1)
plt.plot(procs, procs, marker="", color="grey", linewidth=0.5)
lines = []
for (i, config) in enumerate(configs):
speedups = map(lambda p: baseline / averageAfterWarmup(config, p), procs)
color = colors[i % len(colors)]
marker = markers[i % len(markers)]
linestyle = linestyles[i / len(markers)]
lines.append(plt.plot(procs, speedups, marker=marker, markersize=markerSize, linewidth=1, color=color, linestyle=linestyle))
# this sets the legend.
font = {
'size': legendFontSize,
#'family' : 'normal',
#'weight' : 'bold',
}
matplotlib.rc('font', **font)
# make sure to use truetype fonts
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
# set legend position
matplotlib.rcParams['legend.loc'] = 'upper left'
plt.xlabel('Processors', fontsize=fontSize)
plt.ylabel('Speedup', fontsize=fontSize)
plt.yticks(procs, fontsize=fontSize)
plt.xticks(procs, fontsize=fontSize)
plt.gca().grid(axis='both', linestyle='dotted')
plt.gca().set_axisbelow(True)
# plt.margins(y=10)
plt.legend([b[0] for b in lines], map(renameConfig, configs))
outputName = 'figures/shootout-speedups.pdf'
plt.savefig(outputName, bbox_inches='tight')
sys.stdout.write("[INFO] output written to {}\n".format(outputName))
# ==========================================================================
def makeBold(s):
return "{\\bf " + s + "}"
def textsf(s):
return "\\textsf{" + s + "}"
def display(x):
if x < 1.0:
return "{:.3f}".format(x)
elif x < 10.0:
return "{:.2f}".format(x)
elif x < 100.0:
return "{:.1f}".format(x)
else:
return str(int(round(x)))
tableFile = 'figures/shootout-table.tex'
def makeTableRow(config):
c = config
row = [averageAfterWarmup(c, 1), averageAfterWarmup(c, 70), maxRes(c, 1), maxRes(c, 70)]
row = map(lambda x: display(x) if x is not None else "--", row)
row = [textsf(renameConfig(c))] + row
row = row if c != 'mpl-cc' else map(makeBold, row)
return " & ".join(row)
with open(tableFile, 'w') as f:
for c in configs:
f.write(makeTableRow(c) + " \\\\\n")
sys.stdout.write("[INFO] table rows written to {}\n".format(tableFile))