forked from Mirror/wren
Make run_bench compatible with Python 3
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import math
|
import math
|
||||||
@ -88,8 +90,8 @@ def run_trial(benchmark, language):
|
|||||||
if match:
|
if match:
|
||||||
return float(match.group(1))
|
return float(match.group(1))
|
||||||
else:
|
else:
|
||||||
print "Incorrect output:"
|
print("Incorrect output:")
|
||||||
print out
|
print(out)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -102,11 +104,11 @@ def run_benchmark_language(benchmark, language, benchmark_result):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
name = "{0} - {1}".format(benchmark[0], language[0])
|
name = "{0} - {1}".format(benchmark[0], language[0])
|
||||||
print "{0:30s}".format(name),
|
print("{0:30s}".format(name), end='')
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(
|
if not os.path.exists(os.path.join(
|
||||||
BENCHMARK_DIR, benchmark[0] + language[2])):
|
BENCHMARK_DIR, benchmark[0] + language[2])):
|
||||||
print "No implementation for this language"
|
print("No implementation for this language")
|
||||||
return
|
return
|
||||||
|
|
||||||
times = []
|
times = []
|
||||||
@ -141,7 +143,7 @@ def run_benchmark_language(benchmark, language, benchmark_result):
|
|||||||
if ratio < 95:
|
if ratio < 95:
|
||||||
comparison = red(comparison)
|
comparison = red(comparison)
|
||||||
|
|
||||||
print " {:5.0f} {:4.2f}s {:s}".format(score, best, comparison)
|
print(" {:5.0f} {:4.2f}s {:s}".format(score, best, comparison))
|
||||||
|
|
||||||
benchmark_result[language[0]] = {
|
benchmark_result[language[0]] = {
|
||||||
"desc": name,
|
"desc": name,
|
||||||
@ -169,7 +171,7 @@ def run_benchmark(benchmark, languages):
|
|||||||
|
|
||||||
|
|
||||||
def graph_results(benchmark_result):
|
def graph_results(benchmark_result):
|
||||||
print
|
print('\n')
|
||||||
|
|
||||||
INCREMENT = {
|
INCREMENT = {
|
||||||
'-': 'o',
|
'-': 'o',
|
||||||
@ -184,14 +186,14 @@ def graph_results(benchmark_result):
|
|||||||
score = get_score(min(result["times"]))
|
score = get_score(min(result["times"]))
|
||||||
if score > highest: highest = score
|
if score > highest: highest = score
|
||||||
|
|
||||||
print "{0:30s}0 {1:66.0f}".format("", highest)
|
print("{0:30s}0 {1:66.0f}".format("", highest))
|
||||||
for language, result in benchmark_result.items():
|
for language, result in benchmark_result.items():
|
||||||
line = ["-"] * 68
|
line = ["-"] * 68
|
||||||
for time in result["times"]:
|
for time in result["times"]:
|
||||||
index = int(get_score(time) / highest * 67)
|
index = int(get_score(time) / highest * 67)
|
||||||
line[index] = INCREMENT[line[index]]
|
line[index] = INCREMENT[line[index]]
|
||||||
print "{0:30s}{1}".format(result["desc"], "".join(line))
|
print("{0:30s}{1}".format(result["desc"], "".join(line)))
|
||||||
print
|
print('\n')
|
||||||
|
|
||||||
|
|
||||||
def read_baseline():
|
def read_baseline():
|
||||||
@ -205,7 +207,7 @@ def read_baseline():
|
|||||||
|
|
||||||
|
|
||||||
def generate_baseline():
|
def generate_baseline():
|
||||||
print "generating baseline"
|
print("generating baseline")
|
||||||
baseline_text = ""
|
baseline_text = ""
|
||||||
for benchmark in BENCHMARKS:
|
for benchmark in BENCHMARKS:
|
||||||
best = run_benchmark_language(benchmark, LANGUAGES[0], {})
|
best = run_benchmark_language(benchmark, LANGUAGES[0], {})
|
||||||
@ -220,8 +222,8 @@ def print_html():
|
|||||||
'''Print the results as an HTML chart.'''
|
'''Print the results as an HTML chart.'''
|
||||||
|
|
||||||
def print_benchmark(benchmark, name):
|
def print_benchmark(benchmark, name):
|
||||||
print '<h3>{}</h3>'.format(name)
|
print('<h3>{}</h3>'.format(name))
|
||||||
print '<table class="chart">'
|
print('<table class="chart">')
|
||||||
|
|
||||||
# Scale everything by the highest score.
|
# Scale everything by the highest score.
|
||||||
highest = 0
|
highest = 0
|
||||||
@ -239,11 +241,11 @@ def print_html():
|
|||||||
css_class = "chart-bar"
|
css_class = "chart-bar"
|
||||||
if language == "wren":
|
if language == "wren":
|
||||||
css_class += " wren"
|
css_class += " wren"
|
||||||
print ' <tr>'
|
print(' <tr>')
|
||||||
print ' <th>{}</th><td><div class="{}" style="width: {}%;">{} </div></td>'.format(
|
print(' <th>{}</th><td><div class="{}" style="width: {}%;">{} </div></td>'.format(
|
||||||
language, css_class, ratio, score)
|
language, css_class, ratio, score))
|
||||||
print ' </tr>'
|
print(' </tr>')
|
||||||
print '</table>'
|
print('</table>')
|
||||||
|
|
||||||
print_benchmark("method_call", "Method Call")
|
print_benchmark("method_call", "Method Call")
|
||||||
print_benchmark("delta_blue", "DeltaBlue")
|
print_benchmark("delta_blue", "DeltaBlue")
|
||||||
|
|||||||
Reference in New Issue
Block a user