Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68031 > unrolled thread

Python performance

Started byJCosta <generalcosta@gmail.com>
First post2014-03-08 04:53 -0800
Last post2014-03-08 13:56 -0500
Articles 7 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Python performance JCosta <generalcosta@gmail.com> - 2014-03-08 04:53 -0800
    Re: Python performance Chris Angelico <rosuav@gmail.com> - 2014-03-09 00:24 +1100
    Re: Python performance Tim Chase <python.list@tim.thechases.com> - 2014-03-08 07:40 -0600
    Re: Python performance Marko Rauhamaa <marko@pacujo.net> - 2014-03-08 19:48 +0200
    Re: Python performance JCosta <generalcosta@gmail.com> - 2014-03-08 10:30 -0800
      Re: Python performance Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-08 18:49 +0000
    Re: Python performance Ned Batchelder <ned@nedbatchelder.com> - 2014-03-08 13:56 -0500

#68031 — Python performance

FromJCosta <generalcosta@gmail.com>
Date2014-03-08 04:53 -0800
SubjectPython performance
Message-ID<290bb6ed-a17e-45e3-8ff7-e58bb50e66a6@googlegroups.com>
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

[toc] | [next] | [standalone]


#68034

FromChris Angelico <rosuav@gmail.com>
Date2014-03-09 00:24 +1100
Message-ID<mailman.7928.1394285065.18130.python-list@python.org>
In reply to#68031
On Sat, Mar 8, 2014 at 11:53 PM, JCosta <generalcosta@gmail.com> 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? :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#68038

FromTim Chase <python.list@tim.thechases.com>
Date2014-03-08 07:40 -0600
Message-ID<mailman.7930.1394286032.18130.python-list@python.org>
In reply to#68031
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



[toc] | [prev] | [next] | [standalone]


#68046

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-08 19:48 +0200
Message-ID<87lhwktwdd.fsf@elektro.pacujo.net>
In reply to#68031
JCosta <generalcosta@gmail.com>:

> 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 ?

Yes. The main reason is the dot notation, which in C through Java is
implemented by the compiler as a fixed offset to a memory structure.
High-level programming languages such as Python implement it through a
hash table lookup.

That's the price of keeping everything dynamic: the structural content
is free to change any time during the execution of the program. I have
heard (but not experienced first-hand) that some ingenious heuristic
optimizations have made Common Lisp code come close to C-style
performance. Google was gung ho about repeating the feat on Python, but
seem to have given up.

The second costly specialty of Python is the way objects are
instantiated. Each object is given a "personalized" dispatch table. That
costs time and memory but is extremely nice for the programmer.

In a word, Python is a godsend if its performance is good enough for
your needs. For other needs, you have other programming languages, and
you buy the performance dearly.

Java is a great programming language, as C# must also be. However, for
the needs where you need to drop out of Python, one must ask if you
weren't better off writing some core parts in C and integrating them
with Python.


Marko

[toc] | [prev] | [next] | [standalone]


#68047

FromJCosta <generalcosta@gmail.com>
Date2014-03-08 10:30 -0800
Message-ID<d8f065b8-6ed3-47ff-8239-b059804aa785@googlegroups.com>
In reply to#68031
Sábado, 8 de Março de 2014 12:53:57 UTC, JCosta escreveu:
> 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

...............

Thanks for the help (Chris, Tim and Marko) and  it´s clear now for me ...

[toc] | [prev] | [next] | [standalone]


#68048

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-08 18:49 +0000
Message-ID<mailman.7934.1394304606.18130.python-list@python.org>
In reply to#68047
On 08/03/2014 18:30, JCosta wrote:
> Sábado, 8 de Março de 2014 12:53:57 UTC, JCosta escreveu:
>> 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
>
> ...............
>
> Thanks for the help (Chris, Tim and Marko) and  it´s clear now for me ...
>

You might like to check this out 
https://wiki.python.org/moin/PythonSpeed/PerformanceTips

Would you also please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing and single line paragraphs above, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#68049

FromNed Batchelder <ned@nedbatchelder.com>
Date2014-03-08 13:56 -0500
Message-ID<mailman.7935.1394304975.18130.python-list@python.org>
In reply to#68031
On 3/8/14 7:53 AM, 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 ?
> Thanks
>

Your question, and the replies so far in this thread, have overlooked 
the difference between language and implementation.  Python as a 
language has no inherent speed.  Your question is really about CPython, 
the reference and most-common implementation of the language.  It 
interprets virtual-machine bytecode, and so will pay a penalty for 
compute-bound code.

But PyPy is another implementation of Python.  It uses a JIT to produce 
native code automatically, and can impressively speed up the execution 
of Python programs.  You should give it a try to see if it will help in 
your situation.

-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web