Python and STL efficiency

Pebblestone hadeshuang at gmail.com
Fri Aug 25 18:39:08 EDT 2006


> 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).



Here's the memory usage:

1) before the loop ( fully garbage collected)
29,052,560 bytes, 757,774 objects.

2) after the loop
103,631,952 bytes, 8,760,495 objects.

It seems A has consumed 74M bytes, 8bytes each cell. That make sense
because a cell in list consists of 2 pointers, (car cdr), and an mem
address is 32 bit.





bearophileHUGS at lycos.com wrote:
> 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