benchmarks: Allow for the specification of a base directory for either interpreter

http://hg.python.org/benchmarks/rev/61768f86170c changeset: 164:61768f86170c user: Brett Cannon <brett@python.org> date: Fri Aug 31 18:58:24 2012 -0400 summary: Allow for the specification of a base directory for either interpreter being run. This allows for comparing Python 2.x to Python 3.x by having a Python 2 copy of the benchmarks and Python 3 copy of the benchmarks and then specifying the proper directory:: benchmarks_py3k$ python3 perf.py --basedir /some/py2/benchmark `which python2.7` `which python3.2` files: perf.py | 39 ++++++++++++++++++++++++++++++++------- 1 files changed, 32 insertions(+), 7 deletions(-) diff --git a/perf.py b/perf.py --- a/perf.py +++ b/perf.py @@ -850,8 +850,14 @@ "-exec", "rm", "-f", "{}", ";"]) -def Relative(path): - return os.path.join(os.path.dirname(__file__), path) +def Relative(path, python=None, options=None): + basedir = os.path.dirname(__file__) + if python is not None: + if python[0] == options.base_binary: + basedir = options.control_dirname + else: + basedir = options.experimental_dirname + return os.path.join(basedir, path) def LogCall(command): @@ -1258,9 +1264,9 @@ def Measure2to3(python, options): - fast_target = Relative("lib/2to3/lib2to3/refactor.py") - two_to_three_bin = Relative("lib/2to3/2to3") - two_to_three_dir = Relative("lib/2to3_data") + fast_target = Relative("lib/2to3/lib2to3/refactor.py", python, options) + two_to_three_bin = Relative("lib/2to3/2to3", python, options) + two_to_three_dir = Relative("lib/2to3_data", python, options) env = BuildEnv({"PYTHONPATH": two_to_three_dir}, inherit_env=options.inherit_env) @@ -1471,8 +1477,8 @@ def MeasureMako(python, options): - bm_path = Relative("performance/bm_mako.py") - mako_path = Relative("lib/mako") + bm_path = Relative("performance/bm_mako.py", python, options) + mako_path = Relative("lib/mako", python, options) bm_env = BuildEnv({"PYTHONPATH": mako_path}, options.inherit_env) return MeasureGeneric(python, options, bm_path, bm_env, iteration_scaling=5) @@ -2086,6 +2092,13 @@ """Parser callback to --inherit_env var names.""" parser.values.inherit_env = [v for v in value.split(",") if v] +def ParseBasedirOption(python_args_opt): + default = os.path.dirname(__file__) + parts = python_args_opt.split(",") + if len(parts) == 1: # No comma + parts.append('') + return [path or default for path in parts] + def ParseOutputStyle(option, opt_str, value, parser): if value not in ("normal", "table"): @@ -2142,6 +2155,15 @@ help=("Comma-separated list of environment variable names" " that are inherited from the parent environment" " when running benchmarking subprocesses.")) + parser.add_option("--basedir", default="", + help=("A comma-separated pair of base directories to " + "use when calculating absolute file paths to " + "benchmark and library code. The first argument " + "is for the base interpreter, the second for the " + "experimental one. Any unspecified value is " + "assumed to be the directory containing this " + "file. This is typically used when comparing a " + "Python 2.x interpreter to a 3.x one.")) parser.add_option("-T", "--disable_timelines", default=False, action="store_true", help="Don't use Google charts for displaying timelines.") parser.add_option("-O", "--output_style", metavar="STYLE", type="string", @@ -2184,6 +2206,9 @@ base_cmd_prefix = [base] + base_args changed_cmd_prefix = [changed] + changed_args + basedirs = ParseBasedirOption(options.basedir) + options.control_dirname, options.experimental_dirname = basedirs + logging.basicConfig(level=logging.INFO) if options.track_memory: -- Repository URL: http://hg.python.org/benchmarks
participants (1)
-
brett.cannon