where python is slower?

Peter Hansen peter at engcorp.com
Wed Feb 5 09:19:06 EST 2003


> Enrique Palomo wrote:
> 
> At job, i must work with great size text files (up to 2 Gb)
> I use python cause of its facility to work with strings.
> But python is slower than others programming languages.
> 
> It´s not, by the moment, a big problem, but i would like to speed up the
> code with C.

Read Holger's reply, twice.

Then follow this advice:  first make your program work properly,
*then* measure its performance and *then*, only if it is unacceptable,
profile it to learn where the bottlenecks really are, and only
*then* try to optimize it.  Also, learn to set the threshold for
"unacceptable" very high, and you'll save yourself a lot of effort.

My guess is that you are writing "non-Pythonic" code, which does
things like processing files one character at a time the way you
would in C.  Once you've improved the way you write your Python
code, I believe it is unlikely you will still be concerned about
its performance, because then you will be taking proper advantage
of those parts of Python which are *not* slower than "other languages".

-Peter




More information about the Python-list mailing list