Python performance

Tim Chase python.list at tim.thechases.com
Sat Mar 8 08:40:48 EST 2014


On 2014-03-08 04:53, JCosta wrote:
> I did some work in c# and java and I converted some application to
> Python; I noticed Python is much slower than the other languages.
> 
> Is this normal ?

It depends.

Did you write C#/Java in Python (i.e., use C# or Java idioms in
Python), or did you write Pythonic code?

Check your algorithms and storage classes for performance
characteristics (if you used an O(1) algorithm/container in C#/Java
but used an O(N) algorithm/container in Python) and make sure they
match.

What sorts of operations are you doing?  Are you CPU-bound, I/O
bound, or memory-bound?  Have you profiled to see where the hot-spots
are?

Personally, I've found that most of my code is I/O-bound (disk or
network), and that very rarely has CPU been much of a problem
(usually checking my algorithm if there's trouble; occasionally I'm
stuck with an O(N^2) algorithm and no language-choice.  For some
folks, using one of the specialty-math libraries can speed up numeric
processing.  If I know that memory could be an issue, I tend to switch
to a disk-based data-stores to head off any trouble.

-tkc







More information about the Python-list mailing list