This is an automated email from the ASF dual-hosted git repository. altay pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/beam.git
commit 0807095812f4f9c83adcbcfa4c2962da4adbadd2 Author: Matthias Feys <matth...@ml6.eu> AuthorDate: Fri May 11 23:32:25 2018 +0200 Futurize tools subpackage --- sdks/python/apache_beam/tools/__init__.py | 1 + .../apache_beam/tools/distribution_counter_microbenchmark.py | 11 ++++++++--- sdks/python/apache_beam/tools/map_fn_microbenchmark.py | 12 +++++++++--- sdks/python/apache_beam/tools/sideinput_microbenchmark.py | 10 ++++++++-- sdks/python/apache_beam/tools/utils.py | 2 ++ sdks/python/tox.ini | 1 + 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/sdks/python/apache_beam/tools/__init__.py b/sdks/python/apache_beam/tools/__init__.py index 7b7c3b3..30ca5c3 100644 --- a/sdks/python/apache_beam/tools/__init__.py +++ b/sdks/python/apache_beam/tools/__init__.py @@ -19,3 +19,4 @@ For internal use only; no backwards-compatibility guarantees. """ +from __future__ import absolute_import diff --git a/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py b/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py index 3e301eb..4f48782 100644 --- a/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py +++ b/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py @@ -23,11 +23,16 @@ Run as python -m apache_beam.tools.distribution_counter_microbenchmark """ +from __future__ import absolute_import +from __future__ import division from __future__ import print_function import random import sys import time +from builtins import range + +from past.utils import old_div from apache_beam.tools import utils @@ -44,7 +49,7 @@ def run_benchmark(num_runs=100, num_input=10000, seed=time.time()): total_time = 0 random.seed(seed) lower_bound = 0 - upper_bound = sys.maxint + upper_bound = sys.maxsize inputs = generate_input_values(num_input, lower_bound, upper_bound) from apache_beam.transforms import DataflowDistributionCounter print("Number of runs:", num_runs) @@ -57,8 +62,8 @@ def run_benchmark(num_runs=100, num_input=10000, seed=time.time()): counter.add_inputs_for_test(inputs) time_cost = time.time() - start print("Run %d: Total time cost %g sec" % (i+1, time_cost)) - total_time += time_cost/num_input - print("Per element update time cost:", total_time/num_runs) + total_time += old_div(time_cost, num_input) + print("Per element update time cost:", old_div(total_time, num_runs)) if __name__ == '__main__': diff --git a/sdks/python/apache_beam/tools/map_fn_microbenchmark.py b/sdks/python/apache_beam/tools/map_fn_microbenchmark.py index 537b909..6bfd701 100644 --- a/sdks/python/apache_beam/tools/map_fn_microbenchmark.py +++ b/sdks/python/apache_beam/tools/map_fn_microbenchmark.py @@ -30,9 +30,15 @@ Run as python -m apache_beam.tools.map_fn_microbenchmark """ +from __future__ import absolute_import +from __future__ import division from __future__ import print_function import time +from builtins import range +from builtins import zip + +from past.utils import old_div import apache_beam as beam from apache_beam.tools import utils @@ -45,7 +51,7 @@ def run_benchmark(num_maps=100, num_runs=10, num_elements_step=1000): num_elements = num_elements_step * run + 1 start = time.time() with beam.Pipeline() as p: - pc = p | beam.Create(range(num_elements)) + pc = p | beam.Create(list(range(num_elements))) for ix in range(num_maps): pc = pc | 'Map%d' % ix >> beam.FlatMap(lambda x: (None,)) timings[num_elements] = time.time() - start @@ -55,9 +61,9 @@ def run_benchmark(num_maps=100, num_runs=10, num_elements_step=1000): print # pylint: disable=unused-variable gradient, intercept, r_value, p_value, std_err = stats.linregress( - *zip(*timings.items())) + *list(zip(*list(timings.items())))) print("Fixed cost ", intercept) - print("Per-element ", gradient / num_maps) + print("Per-element ", old_div(gradient, num_maps)) print("R^2 ", r_value**2) diff --git a/sdks/python/apache_beam/tools/sideinput_microbenchmark.py b/sdks/python/apache_beam/tools/sideinput_microbenchmark.py index 15e1b9b..df36174 100644 --- a/sdks/python/apache_beam/tools/sideinput_microbenchmark.py +++ b/sdks/python/apache_beam/tools/sideinput_microbenchmark.py @@ -22,9 +22,14 @@ Run as python -m apache_beam.tools.sideinput_microbenchmark """ +from __future__ import absolute_import +from __future__ import division from __future__ import print_function import time +from builtins import range + +from past.utils import old_div from apache_beam.runners.worker import opcounters from apache_beam.runners.worker import sideinputs @@ -64,9 +69,10 @@ def run_benchmark(num_runs=50, input_per_source=4000, num_sources=4): print("Runtimes:", times) - avg_runtime = sum(times)/len(times) + avg_runtime = old_div(sum(times), len(times)) print("Average runtime:", avg_runtime) - print("Time per element:", avg_runtime/(input_per_source * num_sources)) + print("Time per element:", old_div(avg_runtime, (input_per_source * + num_sources))) if __name__ == '__main__': diff --git a/sdks/python/apache_beam/tools/utils.py b/sdks/python/apache_beam/tools/utils.py index d643195..f2a9c21 100644 --- a/sdks/python/apache_beam/tools/utils.py +++ b/sdks/python/apache_beam/tools/utils.py @@ -17,6 +17,8 @@ """Utility functions for all microbenchmarks.""" +from __future__ import absolute_import + import os diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini index 0c238ee..14b6c8b 100644 --- a/sdks/python/tox.ini +++ b/sdks/python/tox.ini @@ -111,6 +111,7 @@ modules = apache_beam/pvalue apache_beam/pvalue_test apache_beam/testing + apache_beam/tools commands = python --version pip --version -- To stop receiving notification emails like this one, please contact al...@apache.org.