469,626 Members | 1,361 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Using Timing function problem.....

Hi... I'm having a few problems here...
I want to input in my function different values and then time each one
to see how long it took to run the function... so right now it doesn't
like the "i" inside my function fibonacci(i) but if I put a constant
it's fine....
any idea on how to approach this?
thanks!
Jonathan

The Code:
================================================== =====

for i in (range(1,30)):
mytime1 = timeit.Timer( 'fibonacci(i)', 'from prl1 import
fibonacci' )
mytime2 = timeit.Timer( 'fibonacci(i)', 'from prl2 import
fibonacci' )

fib1 = mytime1.timeit(1)
fib2 = mytime2.timeit(1)

================================================== =====

The Error:
================================================== =====
Traceback (most recent call last):
File "prl3.py", line 23, in ?
fib1 = mytime1.timeit(1)
File "/usr/lib64/python2.4/timeit.py", line 161, in timeit
timing = self.inner(it, self.timer)
File "<timeit-src>", line 6, in inner
NameError: global name 'i' is not defined
================================================== =====

Jan 25 '07 #1
2 1093
At Thursday 25/1/2007 01:26, kevin wrote:
>Hi... I'm having a few problems here...
I want to input in my function different values and then time each one
to see how long it took to run the function... so right now it doesn't
like the "i" inside my function fibonacci(i) but if I put a constant
it's fine....
You have to build the right *string* to be evaluated...
>for i in (range(1,30)):
mytime1 = timeit.Timer( 'fibonacci(i)', 'from prl1 import
fibonacci' )
for i in (range(1,30)):
mytime1 = timeit.Timer( 'fibonacci(%d)' % i, 'from prl1
import fibonacci' )
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 25 '07 #2
Thanks so much! that did it!
you can tell I'm new with python.. lol...
thanks again..
Jonathan

Jan 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by C.Joseph Drayton | last post: by
2 posts views Thread by Steven D'Aprano | last post: by
2 posts views Thread by julie.siebel | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.