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

mosscliffe mcl.office at googlemail.com
Thu May 10 07:25:26 EDT 2007


Many thanks. I think I see  what you mean.

I will try 'timeit' as well.

Aren't examples wonderful ?

On 10 May, 11:42, Ant <ant... at gmail.com> wrote:
> 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