Python is faster than C

Christian Tismer pirx at python.net
Sun Apr 4 22:54:20 EDT 2004


Christian Tismer wrote:

> Armin Rigo <arigo <at> tunes.org> writes:
> 
> 
>>Again I'm not saying it is trivial to implement it, but that not having
>>to expose for optimization purposes 'xrange' and the whole 'iterator'
>>part of the language would be worth it, in my opinion.

Responding to myself, after chatting with Armin:

> In general, I share Armin's impression, that iterators are nothing else
> but an explicit way to spell optimizations.
> While explicit is better than implicit, in the case of optimizations,
> I believe it is an over-specification, and almost completely in the false
> direction. We have to prove this in a known project, still.

...

> instead you can do it this way:
> 
> it = iter(sequence)
> can_continue = 1
> while can_continue:
>   try:
>     for each in it:
>       do_something_with(each)
>   exceptSomeThingWrongWithThis
>     can_continue = some_recovery(each)
>     continue

Well, I agree that this is no excuse for the need for iterators.
Under the assumption that iterators are almost for speed,
which could be gathered otherwise, then my use case is
also a hack for speed.
It would not be needed if exceptions in tight loop weren't
expensive. Actually, with a different layout of exceptions,
they could come at no cost if they are not thrown and slightly
more cost if they are thrown.
This is not exactly my idea but came from Armin.
Maybe the blcok stack is going to be optimized away.

cheers - chris






More information about the Python-list mailing list