Writing an emulator in python - implementation questions (for performance)

greg greg at cosc.canterbury.ac.nz
Thu Nov 12 21:33:53 EST 2009


Santiago Romero wrote:
>>How about
>>    page, index = divmod(address, 16384)
>
>  Surely, much better and faster :-)

Not necessarily, because it involves a function call,
and constructing and deconstructing a result tuple.
If you time them, you may well find that the explicit
shift and mask operations turn out to be faster.

That also goes for any of the other things being
discussed here. Especially if you're used to C, one's
intuitions about speed can go badly astray where
Python is concerned. The only way to be sure is to
measure!

-- 
Greg



More information about the Python-list mailing list