Commit ebff5b35 authored by Raymond Hettinger's avatar Raymond Hettinger

Update timeit to use the new string formatting syntax.

parent 58600c9e
...@@ -79,10 +79,10 @@ else: ...@@ -79,10 +79,10 @@ else:
# being indented 8 spaces. # being indented 8 spaces.
template = """ template = """
def inner(_it, _timer): def inner(_it, _timer):
%(setup)s {setup}
_t0 = _timer() _t0 = _timer()
for _i in _it: for _i in _it:
%(stmt)s {stmt}
_t1 = _timer() _t1 = _timer()
return _t1 - _t0 return _t1 - _t0
""" """
...@@ -126,9 +126,9 @@ class Timer: ...@@ -126,9 +126,9 @@ class Timer:
stmt = reindent(stmt, 8) stmt = reindent(stmt, 8)
if isinstance(setup, str): if isinstance(setup, str):
setup = reindent(setup, 4) setup = reindent(setup, 4)
src = template % {'stmt': stmt, 'setup': setup} src = template.format(stmt=stmt, setup=setup)
elif hasattr(setup, '__call__'): elif hasattr(setup, '__call__'):
src = template % {'stmt': stmt, 'setup': '_setup()'} src = template.format(stmt=stmt, setup='_setup()')
ns['_setup'] = setup ns['_setup'] = setup
else: else:
raise ValueError("setup is neither a string nor callable") raise ValueError("setup is neither a string nor callable")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment