optimization

Eric Hagemann ehagemann at home.com
Tue May 9 21:24:58 EDT 2000


Anybody know of work done along the lines of optimizing Python code ? Has
anybody done benchmarks on different coding styles ? Examples of questions
follow

Is it faster to split a string into a tuple with individual elements

>>> a= "as the end"
>>>(x,y,z) = string.split(a," ")
where x = 'as', y = 'the' and z='end'

or as a list

>>>q = string.split(a," " )
where following accesses would entail q[0]='as' etc.

Is is faster to index through a list

>>>a=[1,2,3,4.....]

>>>for i in range(4):
>>>   a[i].....

or

>>>for x in a:
>>>    .......

The answer (as I have found) out is the second.  I am not looking for
specific answers about these questions but they represent the type of
information I seek.  I am looking in general to produce quick code and am
looking for coding techniques that are best utilize the language.

Cheers
Eric






More information about the Python-list mailing list