From c34b4f7de5e97de5103f4ad92ac965c9962f3d41 Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 6 Feb 2015 10:29:13 +0800 Subject: [PATCH] some modifications in demos/benchmark so it can run both in py2 and py3 --- demos/benchmark/benchmark.py | 5 +++++ demos/benchmark/gen_benchmark.py | 4 ++-- demos/benchmark/stack_context_benchmark.py | 2 +- demos/benchmark/template_benchmark.py | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/demos/benchmark/benchmark.py b/demos/benchmark/benchmark.py index 218ab8ed7..6a0354d35 100755 --- a/demos/benchmark/benchmark.py +++ b/demos/benchmark/benchmark.py @@ -22,6 +22,11 @@ import random import signal import subprocess +try: + xrange +except NameError: + xrange = range + # choose a random port to avoid colliding with TIME_WAIT sockets left over # from previous runs. define("min_port", type=int, default=8000) diff --git a/demos/benchmark/gen_benchmark.py b/demos/benchmark/gen_benchmark.py index adbe44fc8..1b5281fb9 100644 --- a/demos/benchmark/gen_benchmark.py +++ b/demos/benchmark/gen_benchmark.py @@ -38,10 +38,10 @@ def main(): parse_command_line() t = Timer(e1) results = t.timeit(options.num) / options.num - print 'engine: %0.3f ms per iteration' % (results * 1000) + print('engine: %0.3f ms per iteration' % (results * 1000)) t = Timer(c1) results = t.timeit(options.num) / options.num - print 'coroutine: %0.3f ms per iteration' % (results * 1000) + print('coroutine: %0.3f ms per iteration' % (results * 1000)) if __name__ == '__main__': main() diff --git a/demos/benchmark/stack_context_benchmark.py b/demos/benchmark/stack_context_benchmark.py index 57c7dd226..43d003c29 100755 --- a/demos/benchmark/stack_context_benchmark.py +++ b/demos/benchmark/stack_context_benchmark.py @@ -68,7 +68,7 @@ def main(): 'ExceptionBenchmark().call_wrapped(500)', ] for cmd in cmds: - print cmd + print(cmd) subprocess.check_call(base_cmd + [cmd]) if __name__ == '__main__': diff --git a/demos/benchmark/template_benchmark.py b/demos/benchmark/template_benchmark.py index a38c689c9..1114b1f4e 100755 --- a/demos/benchmark/template_benchmark.py +++ b/demos/benchmark/template_benchmark.py @@ -57,11 +57,11 @@ def render(): def main(): parse_command_line() if options.dump: - print tmpl.code + print(tmpl.code) sys.exit(0) t = Timer(render) results = t.timeit(options.num) / options.num - print '%0.3f ms per iteration' % (results*1000) + print('%0.3f ms per iteration' % (results*1000)) if __name__ == '__main__': main() -- 2.47.2