New submission from Peter Otten <[EMAIL PROTECTED]>: 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()) 0.54068493843078613 # my patch >>> min(mt.Timer("f(42)", ns=dict(f=f)).repeat()) 0.29009604454040527 - it is more flexible. Example: # working code, requires matplotlib from timeit import Timer from time import sleep def linear(i): sleep(.05*i) def quadratic(i): sleep(.01*i**2) 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) show() 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. ---------- components: Library (Lib) files: diff_against_2_5_1.txt messages: 64805 nosy: potten severity: normal status: open title: Pass a namespace to timeit type: feature request versions: Python 2.6 Added file: http://bugs.python.org/file9916/diff_against_2_5_1.txt __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2527> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com