Message64805
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. |
|
Date |
User |
Action |
Args |
2008-04-01 12:13:47 | peter.otten | set | spambayes_score: 0.047785 -> 0.047785 recipients:
+ peter.otten |
2008-04-01 12:13:47 | peter.otten | set | spambayes_score: 0.047785 -> 0.047785 messageid: <1207052027.28.0.27225375953.issue2527@psf.upfronthosting.co.za> |
2008-04-01 12:13:46 | peter.otten | link | issue2527 messages |
2008-04-01 12:13:45 | peter.otten | create | |
|