using timeit for a function in a class

flupke flupke at nonexistingdomain.com
Thu May 26 18:56:48 EDT 2005


Fredrik Lundh wrote:
> "flupke" wrote:
> 
> 
>>i tried to use timeit on a function in a class but it doesn't do what i
>>think it should do ie. time :)
>>In stead it starts printing line after line of hello time test!
>>What am i doing wrong in order to time the f function?
> 
> 
> how do you expect timeit to figure out how long it takes to run your
> function without calling the function?
> 
> 
>>class TimeTest(object):
>>    def f(self):
>>        print "hello time test!"
> 
> 
> </F> 
> 
> 
>

? i think you missed some of the code
...
     s = """
     test = TimeTest()
     test.f()
     """
...

So the function is being called (as i said, it prints the hello message).

Regards,
Benedict



More information about the Python-list mailing list