From 0fa6da74ccb4f3687fdbd625d43b9e65740e29bc Mon Sep 17 00:00:00 2001 From: Ivor Blockley Date: Tue, 18 Jul 2017 15:17:28 +1000 Subject: [PATCH] Update benchmarks for Python3 while retaining backwards compatibility with Python2 --- benchmark/carsales_proto.py | 4 ++-- benchmark/carsales_pycapnp.py | 4 ++-- benchmark/catrank_proto.py | 10 +++++++--- benchmark/catrank_pycapnp.py | 10 +++++++--- benchmark/eval_proto.py | 4 ++-- benchmark/eval_pycapnp.py | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/benchmark/carsales_proto.py b/benchmark/carsales_proto.py index 5bdcd17..c969070 100755 --- a/benchmark/carsales_proto.py +++ b/benchmark/carsales_proto.py @@ -25,7 +25,7 @@ def random_car(car): car.length = 170 + rand_int(150) car.width = 48 + rand_int(36) car.height = 54 + rand_int(48) - car.weight = car.length * car.width * car.height / 200 + car.weight = car.length * car.width * car.height // 200 engine = car.engine engine.horsepower = 100 * rand_int(400) @@ -51,7 +51,7 @@ def calc_value(car): result += wheel.diameter * wheel.diameter result += 100 if wheel.snow_tires else 0 - result += car.length * car.width * car.height / 50 + result += car.length * car.width * car.height // 50 engine = car.engine result += engine.horsepower * 40 diff --git a/benchmark/carsales_pycapnp.py b/benchmark/carsales_pycapnp.py index c545f8a..d6ed6f2 100755 --- a/benchmark/carsales_pycapnp.py +++ b/benchmark/carsales_pycapnp.py @@ -25,7 +25,7 @@ def random_car(car): car.length = 170 + rand_int(150) car.width = 48 + rand_int(36) car.height = 54 + rand_int(48) - car.weight = car.length * car.width * car.height / 200 + car.weight = car.length * car.width * car.height // 200 engine = car.init('engine') engine.horsepower = 100 * rand_int(400) @@ -51,7 +51,7 @@ def calc_value(car): result += wheel.diameter * wheel.diameter result += 100 if wheel.snowTires else 0 - result += car.length * car.width * car.height / 50 + result += car.length * car.width * car.height // 50 engine = car.engine result += engine.horsepower * 40 diff --git a/benchmark/catrank_proto.py b/benchmark/catrank_proto.py index d91822e..7658d41 100755 --- a/benchmark/catrank_proto.py +++ b/benchmark/catrank_proto.py @@ -2,8 +2,12 @@ from common import rand_int, rand_double, rand_bool, WORDS, from_bytes_helper from random import choice -from string import letters -from itertools import izip +from string import ascii_letters +try: + # Python 2 + from itertools import izip +except ImportError: + izip = zip import catrank_pb2 class Benchmark: @@ -22,7 +26,7 @@ class Benchmark: result = request.result.add() result.score = 1000 - i url_size = rand_int(100) - result.url = "http://example.com/" + ''.join([choice(letters) for _ in range(url_size)]) + result.url = "http://example.com/" + ''.join([choice(ascii_letters) for _ in range(url_size)]) isCat = rand_bool() isDog = rand_bool() diff --git a/benchmark/catrank_pycapnp.py b/benchmark/catrank_pycapnp.py index a1cb67a..6977fe3 100755 --- a/benchmark/catrank_pycapnp.py +++ b/benchmark/catrank_pycapnp.py @@ -4,8 +4,12 @@ import capnp import catrank_capnp from common import rand_int, rand_double, rand_bool, WORDS from random import choice -from string import letters -from itertools import izip +from string import ascii_letters +try: + # Python 2 + from itertools import izip +except ImportError: + izip = zip class Benchmark: def __init__(self, compression): @@ -29,7 +33,7 @@ class Benchmark: for i, result in enumerate(results): result.score = 1000 - i url_size = rand_int(100) - result.url = "http://example.com/" + ''.join([choice(letters) for _ in range(url_size)]) + result.url = "http://example.com/" + ''.join([choice(ascii_letters) for _ in range(url_size)]) isCat = rand_bool() isDog = rand_bool() diff --git a/benchmark/eval_proto.py b/benchmark/eval_proto.py index b7f79ec..f40ba18 100755 --- a/benchmark/eval_proto.py +++ b/benchmark/eval_proto.py @@ -28,7 +28,7 @@ def div(a, b): if a == MIN_INT and b == -1: return MAX_INT - return a / b + return a // b def mod(a, b): if b == 0: @@ -109,4 +109,4 @@ class Benchmark: response.value = evaluate_expression(request) def check(self, response, expected): - return response.value == expected \ No newline at end of file + return response.value == expected diff --git a/benchmark/eval_pycapnp.py b/benchmark/eval_pycapnp.py index 913cb54..1af93d9 100755 --- a/benchmark/eval_pycapnp.py +++ b/benchmark/eval_pycapnp.py @@ -29,7 +29,7 @@ def div(a, b): if a == MIN_INT and b == -1: return MAX_INT - return a / b + return a // b def mod(a, b): if b == 0: