Newbie (but improving) - Passing a function name with parameters as a parameter

Ant antroy at gmail.com
Thu May 10 06:42:58 EDT 2007


As Stephan said, you can investigate the timeit module. If you want to
test it your way, wrap up your function call in another function:

On May 10, 9:27 am, mosscliffe <mcl.off... at googlemail.com> wrote:
...
> def timeloop(dofunction,iters=10):
...
>
> def lookup(recs,patterns):
...

> myrecs = ...
>
def test1():
    lookup(myrecs, ['one', 'nomatch'])

def test2():
    lookup(myrecs, ['one', 'two'])

> timeloop(test1, 10)

Using timeit:

t = timeit.Timer("lookup(myrecs, ['one', 'nomatch'])", "from __main__
import *")
print t.timeit(10)

--
Ant.






More information about the Python-list mailing list