This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author peter.otten
Recipients peter.otten
Date 2008-04-01.12:13:44
SpamBayes Score 0.047784984
Marked as misclassified No
Message-id <>
I'd like to suggest a different approach than the one taken in rev. 
54348 to improve timeit's scripting interface: allow passing it a 
namespace. Reasons:

- It has smaller overhead for functions that take an argument:
>>> def f(a): pass
# trunk
>>> min(ht.Timer(lambda f=f: f(42)).repeat())
# my patch
>>> min(mt.Timer("f(42)", ns=dict(f=f)).repeat())

- it is more flexible. Example:
# working code, requires matplotlib
from timeit import Timer
from time import sleep

def linear(i):
def quadratic(i):

x = range(10)
y = []
for a in x:
    y.append([min(Timer("f(a)", ns=dict(f=f, a=a)).repeat(1, 1))
              for f in linear, quadratic])

from pylab import plot, show
plot(x, y)

The above code works unaltered inside a function, unlike the hacks 
using "from __main__ import ...".

- the implementation is simpler and should be easy to maintain.

The provided patch is against 2.5.1. If it has a chance of being 
accepted I'm willing to jump through the necessary hoops: 
documentation, tests, etc.
Date User Action Args
2008-04-01 12:13:47peter.ottensetspambayes_score: 0.047785 -> 0.047784984
recipients: + peter.otten
2008-04-01 12:13:47peter.ottensetspambayes_score: 0.047785 -> 0.047785
messageid: <>
2008-04-01 12:13:46peter.ottenlinkissue2527 messages
2008-04-01 12:13:45peter.ottencreate