aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRay Glover <ray.glover@uk.ibm.com>2017-03-29 11:39:18 +0100
committerDominic Hamon <dominichamon@users.noreply.github.com>2017-03-29 03:39:18 -0700
commit17298b2dc0e6dc9f78b149ab9256064d0ac96520 (patch)
treedbc23004de64ee494f924be9e959158f8728eb8e /tools
parent0dbcdf56a0d0ed817a7fccf8f622259ee8dafa18 (diff)
downloadgoogle-benchmark-17298b2dc0e6dc9f78b149ab9256064d0ac96520.tar.gz
Python 2/3 compatibility (#361)
* [tools] python 2/3 support * update authors/contributors
Diffstat (limited to 'tools')
-rwxr-xr-xtools/compare_bench.py2
-rw-r--r--tools/gbench/report.py2
-rw-r--r--tools/gbench/util.py22
3 files changed, 13 insertions, 13 deletions
diff --git a/tools/compare_bench.py b/tools/compare_bench.py
index 8a7e799..d54baaa 100755
--- a/tools/compare_bench.py
+++ b/tools/compare_bench.py
@@ -59,7 +59,7 @@ def main():
json1 = gbench.util.run_or_load_benchmark(test1, benchmark_options)
json2 = gbench.util.run_or_load_benchmark(test2, benchmark_options)
output_lines = gbench.report.generate_difference_report(json1, json2)
- print 'Comparing %s to %s' % (test1, test2)
+ print('Comparing %s to %s' % (test1, test2))
for ln in output_lines:
print(ln)
diff --git a/tools/gbench/report.py b/tools/gbench/report.py
index 6776d03..8f1b0fa 100644
--- a/tools/gbench/report.py
+++ b/tools/gbench/report.py
@@ -132,7 +132,7 @@ class TestReportDifference(unittest.TestCase):
json1, json2 = self.load_results()
output_lines_with_header = generate_difference_report(json1, json2, use_color=False)
output_lines = output_lines_with_header[2:]
- print "\n".join(output_lines_with_header)
+ print("\n".join(output_lines_with_header))
self.assertEqual(len(output_lines), len(expect_lines))
for i in xrange(0, len(output_lines)):
parts = [x for x in output_lines[i].split(' ') if x]
diff --git a/tools/gbench/util.py b/tools/gbench/util.py
index bfce376..07c2377 100644
--- a/tools/gbench/util.py
+++ b/tools/gbench/util.py
@@ -20,21 +20,21 @@ def is_executable_file(filename):
"""
if not os.path.isfile(filename):
return False
- with open(filename, 'r') as f:
+ with open(filename, mode='rb') as f:
magic_bytes = f.read(_num_magic_bytes)
if sys.platform == 'darwin':
return magic_bytes in [
- '\xfe\xed\xfa\xce', # MH_MAGIC
- '\xce\xfa\xed\xfe', # MH_CIGAM
- '\xfe\xed\xfa\xcf', # MH_MAGIC_64
- '\xcf\xfa\xed\xfe', # MH_CIGAM_64
- '\xca\xfe\xba\xbe', # FAT_MAGIC
- '\xbe\xba\xfe\xca' # FAT_CIGAM
+ b'\xfe\xed\xfa\xce', # MH_MAGIC
+ b'\xce\xfa\xed\xfe', # MH_CIGAM
+ b'\xfe\xed\xfa\xcf', # MH_MAGIC_64
+ b'\xcf\xfa\xed\xfe', # MH_CIGAM_64
+ b'\xca\xfe\xba\xbe', # FAT_MAGIC
+ b'\xbe\xba\xfe\xca' # FAT_CIGAM
]
elif sys.platform.startswith('win'):
- return magic_bytes == 'MZ'
+ return magic_bytes == b'MZ'
else:
- return magic_bytes == '\x7FELF'
+ return magic_bytes == b'\x7FELF'
def is_json_file(filename):
@@ -68,7 +68,7 @@ def classify_input_file(filename):
elif is_json_file(filename):
ftype = IT_JSON
else:
- err_msg = "'%s' does not name a valid benchmark executable or JSON file"
+ err_msg = "'%s' does not name a valid benchmark executable or JSON file" % filename
return ftype, err_msg
@@ -80,7 +80,7 @@ def check_input_file(filename):
"""
ftype, msg = classify_input_file(filename)
if ftype == IT_Invalid:
- print "Invalid input file: %s" % msg
+ print("Invalid input file: %s" % msg)
sys.exit(1)
return ftype