Skip to content

Commit 9e3f57e

Browse files
committed
Merge pull request #1603 from shahmishal/master
Fix compare_perf_tests.py to support python 3
2 parents 19d13c3 + 046f063 commit 9e3f57e

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

benchmark/scripts/compare_perf_tests.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
# repeat.sh 3 mypatch/bin/Benchmark_Driver run -o -O > mypatch.O.times
1919
# compare_perf_tests.py tot.O.times mypatch.O.times | sort -t, -n -k 6 | column -s, -t
2020

21+
from __future__ import print_function
2122
import re
2223
import sys
2324

25+
2426
VERBOSE = 0
2527

2628
# #,TEST,SAMPLES,MIN(ms),MAX(ms),MEAN(ms),SD(ms),MEDIAN(ms)
@@ -52,7 +54,7 @@ def get_scores(fname):
5254
try:
5355
for line in f:
5456
if VERBOSE:
55-
print("Parsing", line,)
57+
print("Parsing", line, end="")
5658
m = SCORERE.match(line)
5759
is_total = False
5860
if not m:
@@ -85,8 +87,8 @@ def is_max_score(newscore, maxscore, invert):
8587

8688

8789
def compare_scores(key, score1, worstsample1, score2, worstsample2, runs, num):
88-
print(num.rjust(3),)
89-
print(key.ljust(25),)
90+
print(num.rjust(3), end="")
91+
print(key.ljust(25), end="")
9092
bestscore1 = None
9193
bestscore2 = None
9294
worstscore1 = None
@@ -100,7 +102,7 @@ def compare_scores(key, score1, worstsample1, score2, worstsample2, runs, num):
100102
if is_max_score(newscore=score, maxscore=worstscore1, invert=minworst):
101103
worstscore1 = score
102104
if PrintAllScores:
103-
print ("%d" % score).rjust(16),
105+
print (("%d" % score).rjust(16), end="")
104106
for score in worstsample1:
105107
if is_max_score(newscore=score, maxscore=worstscore1, invert=minworst):
106108
worstscore1 = score
@@ -110,47 +112,47 @@ def compare_scores(key, score1, worstsample1, score2, worstsample2, runs, num):
110112
if is_max_score(newscore=score, maxscore=worstscore2, invert=minworst):
111113
worstscore2 = score
112114
if PrintAllScores:
113-
print ("%d" % score).rjust(16),
115+
print (("%d" % score).rjust(16), end="")
114116
r += 1
115117
for score in worstsample2:
116118
if is_max_score(newscore=score, maxscore=worstscore2, invert=minworst):
117119
worstscore2 = score
118120
while r < runs:
119121
if PrintAllScores:
120-
print ("0").rjust(9),
122+
print ("0".rjust(9), end="")
121123
r += 1
122124

123125
if not PrintAllScores:
124-
print ("%d" % bestscore1).rjust(16),
125-
print ("%d" % bestscore2).rjust(16),
126+
print (("%d" % bestscore1).rjust(16), end="")
127+
print (("%d" % bestscore2).rjust(16), end="")
126128

127-
print ("%+d" % (bestscore2 - bestscore1)).rjust(9),
129+
print (("%+d" % (bestscore2 - bestscore1)).rjust(9), end="")
128130

129131
if bestscore1 != 0 and bestscore2 != 0:
130-
print ("%+.1f%%" % (((float(bestscore2) / bestscore1) - 1) * 100)).rjust(9),
132+
print (("%+.1f%%" % (((float(bestscore2) / bestscore1) - 1) * 100)).rjust(9), end="")
131133
if ShowSpeedup:
132134
Num, Den = float(bestscore2), float(bestscore1)
133135
if IsTime:
134136
Num, Den = Den, Num
135-
print ("%.2fx" % (Num / Den)).rjust(9),
137+
print (("%.2fx" % (Num / Den)).rjust(9), end="")
136138
else:
137-
print("*".rjust(9),)
139+
print("*".rjust(9), end="")
138140
if ShowSpeedup:
139-
print("*".rjust(9),)
141+
print("*".rjust(9), end="")
140142
# check if the worst->best interval for each configuration overlap.
141143
if minbest:
142144
if (bestscore1 < bestscore2 and bestscore2 < worstscore1) \
143145
or (bestscore2 < bestscore1 and bestscore1 < worstscore2):
144-
print("(?)",)
146+
print("(?)", end="")
145147
else:
146148
if (worstscore1 < worstscore2 and worstscore2 < bestscore1) \
147149
or (worstscore2 < worstscore1 and worstscore1 < bestscore2):
148-
print("(?)",)
150+
print("(?)", end="")
149151
print()
150152

151153

152154
def print_best_scores(key, scores):
153-
print(key,)
155+
print(key, end="")
154156
bestscore = None
155157
minbest = IsTime
156158
for score in scores:
@@ -194,22 +196,22 @@ def usage():
194196
keys = list(set(scores1.keys() + scores2.keys()))
195197
keys.sort()
196198
if VERBOSE:
197-
print("comparing ", file1, "vs", file2, "=",)
199+
print("comparing ", file1, "vs", file2, "=", end="")
198200
if IsTime:
199201
print(file1, "/", file2)
200202
else:
201203
print(file2, "/", file1)
202204

203-
print("#".rjust(3),)
204-
print("TEST".ljust(25),)
205+
print("#".rjust(3), end="")
206+
print("TEST".ljust(25), end="")
205207
if PrintAllScores:
206208
for i in range(0, runs):
207-
print(("OLD_RUN%d" % i).rjust(9),)
209+
print(("OLD_RUN%d" % i).rjust(9), end="")
208210
for i in range(0, runs):
209-
print(("NEW_RUN%d" % i).rjust(9),)
211+
print(("NEW_RUN%d" % i).rjust(9), end="")
210212
else:
211-
print("BEST_OLD_MIN(μs)".rjust(17),)
212-
print("BEST_NEW_MIN(μs)".rjust(17),)
213+
print("BEST_OLD_MIN(μs)".rjust(17), end="")
214+
print("BEST_NEW_MIN(μs)".rjust(17), end="")
213215
print('DELTA'.rjust(9), '%DELTA'.rjust(9), 'SPEEDUP'.rjust(9))
214216

215217
for key in keys:

0 commit comments

Comments
 (0)