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\n' for compiler in compilers: html += '\t\t\n" html += "\t\n" odd = True for test in tests: html += '\t\n\t\t\n' for compiler in compilers: html += '\t\t\n" html += "\t\n" html += "
Test' + compiler + "
' html += test html += '' #html += "%.3f" % (float(timing) / 1000) html += FormatFunc(timing, test) 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\n\t\t\n\n\t\t\n\t\t\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\n\t\t\n" html += '\t\t\n\t\t\n\t\t\n\t\t\n\t\n' % ( best, toleranceBest, mean, variance ) html += "
CompilerBestWithin 3%MeanVariance
' html += compiler + "%d%d%.2f%.2f
\n\n\n" output = file("report.html", "w") output.write(html) output.close()