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
=============== =============== =============== ========== 2 1208
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
Thanks so much! that did it!
you can tell I'm new with python.. lol...
thanks again..
Jonathan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Russell |
last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull.
I have a modal dialog that is an IFrame.
The IFrame contains another window - which contains the appropriate title.
I am trying to change the title of the IFrame window to be
that of the contained window title.
If I uncomment the alert statement below - the title change works.
Comment out the alert - and - no title change.
|
by: C.Joseph Drayton |
last post by:
I have a problem that I am hoping someone can help me with.
First let me describe the problem. I have an HTML form that in one
field has an onBlur call to a JavaScript function. When you exit the
field, it calls the JavaScript routine, which in turn calls a PHP
script. The PHP script runs returns the value needed. And returns to
the JavaScript. The JavaScript function is then supposed to set
alerts depending on the values returned from...
|
by: OlafMeding |
last post by:
Below are 2 files that isolate the problem. Note, both programs hang
(stop responding) with hyper-threading turned on (a BIOS setting), but
work as expected with hyper-threading turned off.
Note, the Windows task manager shows 2 CPUs on the Performance tab with
hyper-threading is turned on.
Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this
problem.
The operating system is MS Windows XP Professional.
|
by: Steven D'Aprano |
last post by:
The timeit module is ideal for measuring small code snippets; I want to
measure large function objects.
Because the timeit module takes the code snippet argument as a string, it
is quite handy to use from the command line, but it is less convenient for
timing large pieces of code or when working in the interactive
interpreter. E.g. variations on this *don't* work:
$ python
Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
|
by: julie.siebel |
last post by:
Google apparently ate my original post to this (grr) so this'll be a
bit more vague than the initial post, but...*sigh*.
Javascript is not my forte, and I apologize for the acky-ness of the
code.
I'm working on a page for a travel company. There's way too much going
on with it/on it, but I'm kind of stuck at this point - the client
loves it, so I have to solve this problem.
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |