[BangPypers] Tuples vs Lists, perfromance difference

Navin Kabra navin.kabra at gmail.com
Thu Dec 24 02:04:51 CET 2009


On Wed, Dec 23, 2009 at 9:03 PM, Senthil Kumaran <orsenthil at gmail.com>wrote:

> On Wed, Dec 23, 2009 at 11:15:56AM +0530, Vishal wrote:
> > After having everything in Python now, performance is something people
> want
> > to look at. Hence these efforts.
>
> Would you like to explain a bit more on this? Most often with Python
> when I have found people speaking about performance and speed, it has
> been associated either with incorrect expectations or some kind of
> design mistakes which most of us do when we are beginning.
>

Well said. On an average, a program in a dynamic programming language, if it
is CPU bound, is likely to be 10 times slower than one in a static language
(like C/C++ or Java). But, programming in python is still acceptable
because:
  1. Most programs in the world are IO bound (i.e. file IO, database IO or
network IO)
  2. Most programs don't really need the speed.

If #1 is your problem (as is likely), you need to look at the structure and
organization of your program to ensure more efficiency of the IOs. This has
nothing really to do with python, or lists and tuples, and whether a for
loop is faster than a list comprehension.


> Your question on tuples vs lists is very corner case with respect to
> performance. It should hardly matter for most programs. If it did
> matter to you, I would like to know.
>

Agreed. If you find yourself worrying about the performance of lists vs
tuples in a python program, in 90% of the cases, I would think that
something is significantly wrong with the picture. If this is indeed an
important issue to worry about, even I would love to know that use case and
discuss it.


> Also, when I mentioned about expectations, it is clearly wrong for us
> to expect the performance of C++ in Python. A good comparison should
> be Java and I have found interchanging performance differences for
> applications in Java and Python.
>

Huh!?

I think you phenomenally misunderstand the current state of Java.

Performance of Java and C/C++ is likely to be very comparable to each other
(even in case of CPU bound programs). By contrast, a dynamic programming
language like php/python/ruby is likely to be 10x slower then either of
them. See
http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/for
a datapoint and a more detailed discussion.

navin.


More information about the BangPypers mailing list