LISTS: Extract every other element - SUMMARY
Christian Tismer
tismer at appliedbiometrics.com
Sun Dec 19 16:27:41 EST 1999
Mike Fletcher wrote:
Here I see a problem:
> for x in range(5):
> t = time.clock()
> function( data )
> avg.append( time.clock()-t )
> print '%s %.4f'%(function, reduce( lambda x,y: x+y,
The timing must be outside the loop.
Better adjust the loop with a clear run.
But calls into windows cause much uncertaincy,
better avoid them.
I run all my stuff in a small apply loop which is
adjusted against a dry run with apply(len) counted as 0.
def timing(func, args=None, n=1, **keywords) :
import time
time=time.time
appl=apply
if args is None: args = ()
if type(args) != type(()) : args=(args,)
rep=range(n)
dummyarg = ("",)
dummykw = {}
dummyfunc = len
if keywords:
before=time()
for i in rep: res=appl(dummyfunc, dummyarg, dummykw)
empty = time()-before
before=time()
for i in rep: res=appl(func, args, keywords)
else:
before=time()
for i in rep: res=appl(dummyfunc, dummyarg)
empty = time()-before
before=time()
for i in rep: res=appl(func, args)
after = time()
return round(after-before-empty,4), res
ciao - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
More information about the Python-list
mailing list