Efficiency of using long integers to hold bitmaps

"Martin v. Löwis" martin at v.loewis.de
Sun Jul 10 18:51:36 EDT 2005


Bengt Richter wrote:
> Sounds like a possible^H^H^H^H^H^H^H^Hprobable premature optimization worry ;-)

Right. OTOH, I notice a frequent game of Katze und Maus (cat and mouse?)
in questions around Python implementation details. The OP doesn't
provide details of his application, but instead asks a general question
"how is foo implemented in Python, I'm worried it might be bar?". Then,
instead of saying "yes, it is bar" or "no, it isn't bar", the response
is "we can't answer your real question because you didn't state it
well".

In this case, I really liked Raymond's answer (arrays are as efficient
as long ints, which are both more efficient than lists of integers). It
is close enough to the truth for the OP (*), and was stated with much
less text than this message (or the one I'm responding to).

I really should go to bed now,

Martin

(*) even closer to the truth is the observation that arrays are slightly
more space-efficient, because they can store 32 bits in 4 bytes, whereas
long ints only store 30 bits in 4 bytes. Time efficiency is more
difficult to compare, because it depends on the individual
implementation.



More information about the Python-list mailing list