import string, sys
def ReadResults(fname, timings, compilers, tests):
try:
rep = file(fname, "r");
except:
print "Cannot open file"
return False
lines = rep.readlines()
for line in lines:
space = string.find(line, " ")
if space == -1:
continue
compiler = line[:space]
colon = string.find(line, ": ", space+1)
if colon == -1:
continue
test = line[space+1:colon]
space = string.find(line, " ", colon+2)
if space == -1:
continue
time = int(line[colon+2:space])
if not timings.has_key(test):
timings[test] = {}
minTimes[test] = 100000
tests.append(test)
if not compiler in compilers:
compilers.append(compiler)
timings[test][compiler] = time
if (time > 0) and (time < minTimes[test]):
minTimes[test] = time
rep.close()
return True
def PrintResultsTable(tests, compilers, timings, title, FormatFunc):
html = '
' + title + '
\n'
html += '
\n'
html += '\t
\n\t\t
Test
\n'
for compiler in compilers:
html += '\t\t
' + compiler + "
\n"
html += "\t
\n"
odd = True
for test in tests:
html += '\t
\n\t\t
'
html += test
html += '
\n'
for compiler in compilers:
html += '\t\t
'
#html += "%.3f" % (float(timing) / 1000)
html += FormatFunc(timing, test)
html += "
\n"
html += "\t
\n"
html += "
\n\n"
return html
def FormatTimingSeconds(timing, test):
return "%.3f" % (float(timing) / 1000)
def FormatTimingNormalized(timing, test):
normalized = int(float(timing) / minTimes[test] * 100) / 100.0
return "%.2f" % normalized
timings = {}
compilers = []
tests = []
minTimes = {}
if len(sys.argv) < 2:
fname = "benchmark.txt"
else:
fname = sys.argv[1]
if not ReadResults(fname, timings, compilers, tests):
sys.exit(1)
tests.sort()
compilers.sort()
html = '\n\n\tCompiler Shootout\n\t\n\n\n'
html += '\n\n'
html += PrintResultsTable(tests, compilers, timings, 'Times in seconds', FormatTimingSeconds)
html += PrintResultsTable(tests, compilers, timings, 'Normalized performance', FormatTimingNormalized)
html += "
Statistics
\n"
html += '
\n'
html += '\t
\n\t\t
Compiler
\n\t\t
Best
\n
Within 3%
\n\t\t
Mean
\n\t\t
Variance
\n\t
\n'
odd = True
for compiler in compilers:
sum = 0
num = 0
best = 0
toleranceBest = 0
for test in tests:
try:
timing = timings[test][compiler]
except KeyError:
timing = 0
if timing == minTimes[test]:
best += 1
timing = int(float(timing) / minTimes[test] * 100) / 100.0
if timing > 0:
sum += timing
num += 1
if timing <= 1.03:
toleranceBest += 1
mean = float(sum) / num
variance = 0.0
for test in tests:
try:
timing = float(timings[test][compiler]) / minTimes[test]
except KeyError:
timing = 0
if timing > 0:
variance += (timing - mean) * (timing - mean)
variance = variance / num
html += '\t