Python and STL efficiency
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Fri Aug 25 18:19:42 EDT 2006
Pebblestone:
>I heard that python's list is implemented as adjustable array.
Correct, an array geometrically adjustable on the right.
>Here's my lisp implementation:<
What's the memory size of a before computing b? You can compare it with
Python, that may need less memory (because the array contains
pointers).
>BTW, I couldn't install psyco on my system (ubuntu), gcc just prompt to me thousands of lines of errors and warnings.<
Find a Win box ;-) It's already compiled for it (for Py 2.3, 2.4).
>Your python's example (use direct index array index) of my corresponding lisp code works slower than the version which use 'append'.<
For me (a slow PC) it's almost twice faster, computer life is usually
complex.
For me using the esplicit allocation + Psyco makes that program about 4
times faster (from 8 to 2 seconds).
>This let me think how python's list is implemented.<
You also have to think how the * allocation is implemented and many
other things :-)
The list implementation is rather readable, Python sources are online
too.
>Anyway, python's list is surprisingly efficient.<
But its access isn't that fast :-) Psyco helps.
Bye,
bearophile
More information about the Python-list
mailing list