summaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
Diffstat (limited to 'bench')
-rw-r--r--bench/bench.py11
-rw-r--r--bench/env.__setitem__.py21
-rw-r--r--bench/is_types.py8
-rw-r--r--bench/lvars-gvars.py6
-rw-r--r--bench/timeit.py10
5 files changed, 27 insertions, 29 deletions
diff --git a/bench/bench.py b/bench/bench.py
index ef60535..e076e43 100644
--- a/bench/bench.py
+++ b/bench/bench.py
@@ -23,6 +23,7 @@
#
# This will allow (as much as possible) us to time just the code itself,
# not Python function call overhead.
+from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
import getopt
import sys
@@ -93,10 +94,10 @@ exec(open(args[0], 'rU').read())
try:
FunctionList
except NameError:
- function_names = filter(lambda x: x[:4] == FunctionPrefix, locals().keys())
+ function_names = [x for x in locals().keys() if x[:4] == FunctionPrefix]
function_names.sort()
- l = map(lambda f, l=locals(): l[f], function_names)
- FunctionList = filter(lambda f: type(f) == types.FunctionType, l)
+ l = [locals()[f] for f in function_names]
+ FunctionList = [f for f in l if type(f) == types.FunctionType]
IterationList = [None] * Iterations
@@ -104,7 +105,7 @@ def timer(func, *args, **kw):
results = []
for i in range(Runs):
start = Now()
- apply(func, args, kw)
+ func(*args, **kw)
finish = Now()
results.append((finish - start) / Iterations)
return results
@@ -119,7 +120,7 @@ for func in FunctionList:
print func.__name__ + d + ':'
for label, args, kw in Data:
- r = apply(timer, (func,)+args, kw)
+ r = timer(func, *args, **kw)
display(label, r)
# Local Variables:
diff --git a/bench/env.__setitem__.py b/bench/env.__setitem__.py
index d20785a..61d8c1e 100644
--- a/bench/env.__setitem__.py
+++ b/bench/env.__setitem__.py
@@ -6,7 +6,6 @@
import os.path
import re
-import string
import sys
import timeit
@@ -174,7 +173,7 @@ class env_global_regex_is_valid(Environment):
class env_special_set_has_key(Environment):
"""_special_set.get(): use _special_set.has_key() instead"""
def __setitem__(self, key, value):
- if self._special_set.has_key(key):
+ if key in self._special_set:
self._special_set[key](self, key, value)
else:
if not SCons.Environment.is_valid_construction_var(key):
@@ -232,7 +231,7 @@ class env_not_has_key(Environment):
if special:
special(self, key, value)
else:
- if not self._dict.has_key(key) \
+ if key not in self._dict \
and not SCons.Environment.is_valid_construction_var(key):
raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key
self._dict[key] = value
@@ -243,7 +242,7 @@ class env_Best_attribute(Environment):
if key in self._special_set_keys:
self._special_set[key](self, key, value)
else:
- if not self._dict.has_key(key) \
+ if key not in self._dict \
and not global_valid_var.match(key):
raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key
self._dict[key] = value
@@ -251,10 +250,10 @@ class env_Best_attribute(Environment):
class env_Best_has_key(Environment):
"""Best __setitem__(), with has_key"""
def __setitem__(self, key, value):
- if self._special_set.has_key(key):
+ if key in self._special_set:
self._special_set[key](self, key, value)
else:
- if not self._dict.has_key(key) \
+ if key not in self._dict \
and not global_valid_var.match(key):
raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key
self._dict[key] = value
@@ -265,7 +264,7 @@ class env_Best_list(Environment):
if key in ['BUILDERS', 'SCANNERS', 'TARGET', 'TARGETS', 'SOURCE', 'SOURCES']:
self._special_set[key](self, key, value)
else:
- if not self._dict.has_key(key) \
+ if key not in self._dict \
and not global_valid_var.match(key):
raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key
self._dict[key] = value
@@ -278,7 +277,7 @@ else:
class env_isalnum(Environment):
"""Greg's Folly: isalnum instead of probe"""
def __setitem__(self, key, value):
- if self._special_set.has_key(key):
+ if key in self._special_set:
self._special_set[key](self, key, value)
else:
if not key.isalnum() and not global_valid_var.match(key):
@@ -324,7 +323,7 @@ common_import_variables = ['do_it'] + class_names
common_imports = """
from __main__ import %s
-""" % string.join(common_import_variables, ', ')
+""" % ', '.join(common_import_variables)
# The test data (lists of variable names) that we'll use for the runs.
@@ -340,10 +339,10 @@ def run_it(title, init):
s['num'] = iterations
s['title'] = title
s['init'] = init
- apply(times,(),s)
+ times(**s)
print 'Environment __setitem__ benchmark using',
-print 'Python', string.split(sys.version)[0],
+print 'Python', sys.version.split()[0],
print 'on', sys.platform, os.name
run_it('Results for re-adding an existing variable name 100 times:',
diff --git a/bench/is_types.py b/bench/is_types.py
index d225465..f9f7677 100644
--- a/bench/is_types.py
+++ b/bench/is_types.py
@@ -29,11 +29,11 @@ except ImportError:
def __complex__(self): return complex(self.data)
def __hash__(self): return hash(self.data)
- def __cmp__(self, string):
- if isinstance(string, UserString):
- return cmp(self.data, string.data)
+ def __cmp__(self, s):
+ if isinstance(s, UserString):
+ return cmp(self.data, s.data)
else:
- return cmp(self.data, string)
+ return cmp(self.data, s)
def __contains__(self, char):
return char in self.data
diff --git a/bench/lvars-gvars.py b/bench/lvars-gvars.py
index 724b7a2..bdb09ef 100644
--- a/bench/lvars-gvars.py
+++ b/bench/lvars-gvars.py
@@ -19,7 +19,7 @@ def Func1(var, gvars, lvars):
def Func2(var, gvars, lvars):
"""lvars has_key(), gvars try:-except:"""
for i in IterationList:
- if lvars.has_key(var):
+ if var in lvars:
x = lvars[var]
else:
try:
@@ -30,9 +30,9 @@ def Func2(var, gvars, lvars):
def Func3(var, gvars, lvars):
"""lvars has_key(), gvars has_key()"""
for i in IterationList:
- if lvars.has_key(var):
+ if var in lvars:
x = lvars[var]
- elif gvars.has_key(var):
+ elif var in gvars:
x = gvars[var]
else:
x = ''
diff --git a/bench/timeit.py b/bench/timeit.py
index cc087e1..ca7e470 100644
--- a/bench/timeit.py
+++ b/bench/timeit.py
@@ -70,8 +70,6 @@ except ImportError:
# Must be an older Python version (see timeit() below)
itertools = None
-import string
-
__all__ = ["Timer"]
dummy_src_name = "<timeit-src>"
@@ -100,7 +98,7 @@ def inner(_it, _timer):
def reindent(src, indent):
"""Helper to reindent a multi-line statement."""
- return string.replace(src, "\n", "\n" + " "*indent)
+ return src.replace("\n", "\n" + " "*indent)
class Timer:
"""Class for timing execution speed of small code snippets.
@@ -226,7 +224,7 @@ def main(args=None):
print "use -h/--help for command line help"
return 2
timer = default_timer
- stmt = string.join(args, "\n") or "pass"
+ stmt = "\n".join(args) or "pass"
number = 0 # auto-determine
setup = []
repeat = default_repeat
@@ -252,7 +250,7 @@ def main(args=None):
if o in ("-h", "--help"):
print __doc__,
return 0
- setup = string.join(setup, "\n") or "pass"
+ setup = "\n".join(setup) or "pass"
# Include the current directory, so that local imports work (sys.path
# contains the directory of this script, rather than the current
# directory)
@@ -279,7 +277,7 @@ def main(args=None):
return 1
best = min(r)
if verbose:
- print "raw times:", string.join(map(lambda x, p=precision: "%.*g" % (p, x), r))
+ print "raw times:", ' '.join(["%.*g" % (precision, x) for x in r])
print "%d loops," % number,
usec = best * 1e6 / number
if usec < 1000: