Python performance

Chris Angelico rosuav at
Sat Mar 8 14:24:24 CET 2014

On Sat, Mar 8, 2014 at 11:53 PM, JCosta <generalcosta at> 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 ?
> Thanks

The first thing to look at is the conversion. If you convert idiomatic
Java code into the nearest-equivalent Python, it won't be idiomatic
Python, and it'll probably underperform. (This is especially true if
you create a whole lot of objects, use long chains of classes with
dots, and so on. Java follows dotted name chains at compile time,
Python does at run time.)

Another thing to consider is that Python, while very convenient, isn't
always the fastest at heavy numerical computation. For that, there are
some dedicated libraries, like NumPy, which can do that for you.

But it's also worth checking whether the speed difference even
matters. Are you able to see a real difference, as a human, or is this
just benchmarks? It's not a problem for something to take 5ms in
Python that would take 2ms in Java, if that time is spent responding
to a user's click - the user won't see that difference!

If you post a bit of code, we can help you to see what's going on.
Best bit of code to post would be the slowest - and since you're
talking about performance, you _have_ profiled your code and found
which bit's the slowest, right? :)


More information about the Python-list mailing list