summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorGary Oberbrunner <garyo@oberbrunner.com>2013-09-22 13:08:12 -0400
committerGary Oberbrunner <garyo@oberbrunner.com>2013-09-22 13:08:12 -0400
commit895990cbd5007876709b93e6d3db2b6c069382ea (patch)
treeb95b2144ccf82d8227cec025af152f4eadfa7282 /bench
parentf094b77fc68787c61efdc9ca095098c88bf52373 (diff)
downloadscons-895990cbd5007876709b93e6d3db2b6c069382ea.tar.gz
Result of raw 2to3 run (2to3-2.7); checkpoint for python3 conversion.
Diffstat (limited to 'bench')
-rw-r--r--bench/bench.py8
-rw-r--r--bench/env.__setitem__.py16
-rw-r--r--bench/is_types.py12
-rw-r--r--bench/timeit.py24
4 files changed, 30 insertions, 30 deletions
diff --git a/bench/bench.py b/bench/bench.py
index 74dbf121..1a98d8c2 100644
--- a/bench/bench.py
+++ b/bench/bench.py
@@ -23,7 +23,7 @@
#
# This will allow (as much as possible) us to time just the code itself,
# not Python function call overhead.
-from __future__ import division
+
import getopt
import sys
@@ -94,7 +94,7 @@ exec(open(args[0], 'rU').read())
try:
FunctionList
except NameError:
- function_names = sorted([x for x in locals().keys() if x[:4] == FunctionPrefix])
+ function_names = sorted([x for x in list(locals().keys()) if x[:4] == FunctionPrefix])
l = [locals()[f] for f in function_names]
FunctionList = [f for f in l if isinstance(f, types.FunctionType)]
@@ -113,12 +113,12 @@ def display(label, results):
total = 0.0
for r in results:
total += r
- print " %8.3f" % ((total * 1e6) / len(results)), ':', label
+ print(" %8.3f" % ((total * 1e6) / len(results)), ':', label)
for func in FunctionList:
if func.__doc__: d = ' (' + func.__doc__ + ')'
else: d = ''
- print func.__name__ + d + ':'
+ print(func.__name__ + d + ':')
for label, args, kw in Data:
r = timer(func, *args, **kw)
diff --git a/bench/env.__setitem__.py b/bench/env.__setitem__.py
index b17b59e4..284653e8 100644
--- a/bench/env.__setitem__.py
+++ b/bench/env.__setitem__.py
@@ -33,15 +33,15 @@ class Timing(object):
def times(num=1000000, init='', title='Results:', **statements):
# time each statement
timings = []
- for n, s in statements.items():
+ for n, s in list(statements.items()):
t = Timing(n, num, init, s)
t.timeit()
timings.append(t)
- print
- print title
+ print()
+ print(title)
for i in sorted([(i.getResult(),i.name) for i in timings]):
- print " %9.3f s %s" % i
+ print(" %9.3f s %s" % i)
# Import the necessary local SCons.* modules used by some of our
# alternative implementations below, first manipulating sys.path so
@@ -287,7 +287,7 @@ else:
# that the timer will use to get at these classes.
class_names = []
-for n in locals().keys():
+for n in list(locals().keys()):
#if n.startswith('env_'):
if n[:4] == 'env_':
class_names.append(n)
@@ -339,9 +339,9 @@ def run_it(title, init):
s['init'] = init
times(**s)
-print 'Environment __setitem__ benchmark using',
-print 'Python', sys.version.split()[0],
-print 'on', sys.platform, os.name
+print('Environment __setitem__ benchmark using', end=' ')
+print('Python', sys.version.split()[0], end=' ')
+print('on', sys.platform, os.name)
run_it('Results for re-adding an existing variable name 100 times:',
common_imports + """
diff --git a/bench/is_types.py b/bench/is_types.py
index 69c029fc..b6da0d25 100644
--- a/bench/is_types.py
+++ b/bench/is_types.py
@@ -17,11 +17,11 @@ InstanceType = types.InstanceType
DictType = dict
ListType = list
StringType = str
-try: unicode
+try: str
except NameError:
UnicodeType = None
else:
- UnicodeType = unicode
+ UnicodeType = str
# The original implementations, pretty straightforward checks for the
@@ -36,7 +36,7 @@ def original_is_List(e):
if UnicodeType is not None:
def original_is_String(e):
- return isinstance(e, (str,unicode,UserString))
+ return isinstance(e, (str,UserString))
else:
def original_is_String(e):
return isinstance(e, (str,UserString))
@@ -58,7 +58,7 @@ def checkInstanceType_is_List(e):
if UnicodeType is not None:
def checkInstanceType_is_String(e):
return isinstance(e, str) \
- or isinstance(e, unicode) \
+ or isinstance(e, str) \
or (isinstance(e, types.InstanceType) and isinstance(e, UserString))
else:
def checkInstanceType_is_String(e):
@@ -84,7 +84,7 @@ if UnicodeType is not None:
def cache_type_e_is_String(e):
t = type(e)
return t is str \
- or t is unicode \
+ or t is str \
or (t is types.InstanceType and isinstance(e, UserString))
else:
def cache_type_e_is_String(e):
@@ -136,7 +136,7 @@ if UnicodeType is not None:
t = type(obj)
if t is types.InstanceType:
t = instanceTypeMap.get(obj.__class__, t)
- elif t is unicode:
+ elif t is str:
t = str
return t
else:
diff --git a/bench/timeit.py b/bench/timeit.py
index c5fef126..28400109 100644
--- a/bench/timeit.py
+++ b/bench/timeit.py
@@ -46,7 +46,7 @@ be aware of it. The baseline overhead can be measured by invoking the
program without arguments. The baseline overhead differs between
Python versions!
"""
-from __future__ import division
+
try:
import gc
@@ -122,7 +122,7 @@ class Timer(object):
self.src = src # Save for traceback display
code = compile(src, dummy_src_name, "exec")
ns = {}
- exec code in globals(), ns
+ exec(code, globals(), ns)
self.inner = ns["inner"]
def print_exc(self, file=None):
@@ -216,9 +216,9 @@ def main(args=None):
opts, args = getopt.getopt(args, "n:s:r:tcvh",
["number=", "setup=", "repeat=",
"time", "clock", "verbose", "help"])
- except getopt.error, err:
- print err
- print "use -h/--help for command line help"
+ except getopt.error as err:
+ print(err)
+ print("use -h/--help for command line help")
return 2
timer = default_timer
stmt = "\n".join(args) or "pass"
@@ -245,7 +245,7 @@ def main(args=None):
precision = precision + 1
verbose = precision + 1
if o in ("-h", "--help"):
- print __doc__,
+ print(__doc__, end=' ')
return 0
setup = "\n".join(setup) or "pass"
# Include the current directory, so that local imports work (sys.path
@@ -264,7 +264,7 @@ def main(args=None):
t.print_exc()
return 1
if verbose:
- print "%d loops -> %.*g secs" % (number, precision, x)
+ print("%d loops -> %.*g secs" % (number, precision, x))
if x >= 0.2:
break
try:
@@ -274,18 +274,18 @@ def main(args=None):
return 1
best = min(r)
if verbose:
- print "raw times:", ' '.join(["%.*g" % (precision, x) for x in r])
- print "%d loops," % number,
+ print("raw times:", ' '.join(["%.*g" % (precision, x) for x in r]))
+ print("%d loops," % number, end=' ')
usec = best * 1e6 / number
if usec < 1000:
- print "best of %d: %.*g usec per loop" % (repeat, precision, usec)
+ print("best of %d: %.*g usec per loop" % (repeat, precision, usec))
else:
msec = usec / 1000
if msec < 1000:
- print "best of %d: %.*g msec per loop" % (repeat, precision, msec)
+ print("best of %d: %.*g msec per loop" % (repeat, precision, msec))
else:
sec = msec / 1000
- print "best of %d: %.*g sec per loop" % (repeat, precision, sec)
+ print("best of %d: %.*g sec per loop" % (repeat, precision, sec))
return None
if __name__ == "__main__":