continue and break frustration
Glen Wheeler
adsl5lcq at tpg.com.au
Sun Dec 14 01:02:30 EST 2003
On 13 Dec 2003 21:44:52 -0800, Paul Rubin
<http://phr.cx@NOSPAM.invalid> wrote:
>Glen Wheeler <adsl5lcq at tpg.com.au> writes:
>> I've been coding in python for a reasonable amount of time now
>> (coding in total for approx. 20 years) and am writing a performance
>> intensive program in python.
>> The problem I'm having is I want to use break and continue to get
>> out from more than one level of loop. If I set a variable and then
>> check it my program will take too much of a performance hit.
>> Are there any alternatives people can think of?
>
>Raise an exception and catch it. However, if your function is that
>sensitive to a little thing like that, maybe you need to write it
>differently, for example in Pyrex or as a C extension. You could
>also try the Psyco compiler.
I've been using the psyco compiler, and it does help (by about 60%).
I'm trying to leave writing the function as a C extension as a last
resort.
I will try with exceptions (get it? :). To the people in the know,
does adding this kind of construct detract from the speed of the code
much? I do know that try+except can be slower than if+else if
exceptions are generated more often than not, but how much slower?
Thanks,
Glen
More information about the Python-list
mailing list