[BangPypers] Tuples vs Lists, perfromance difference

Senthil Kumaran orsenthil at gmail.com
Thu Dec 24 08:35:19 CET 2009


On Thu, Dec 24, 2009 at 12:52:06PM +0530, Vishal wrote:
> What I was thinking is that as a matter of practice, while writing code, is
> it good practice to use tuples, whenever we know that the sequence is not
> going to change at runtime, and only accessing is going to happen.

This is helpful to know. Thanks!
You might want to look at timeit module and certain examples of timeit
to write short snippets to try which was better for your purposes.
And as one of the response pointed out the StackOverflow link the
insertion was faster in tuple. Retrievals were same. 

The standard library module dis can help you see the low level calls.

> 
> Also interesting stuff about the Java comparison. The question remains, why
> the JVM is so fast and why Python is not as far as JVM? I am sure there must
> be a ton of info on this over the net :)

This is simple to answer *in general*.  JVM has a Just in Time
compiler which makes optimizations to already compiled code and
executes it on top of virtual machine. Python on the other hand is
just byte code interpreted. 

The folks at unladen-swallow, are going to use LLVM another virtual
machine with Just In Time compiler support to make Python execution
fast too.


-- 
Senthil
Lay on, MacDuff, and curs'd be him who first cries, "Hold, enough!".
		-- Shakespeare


More information about the BangPypers mailing list