int() 24 times slower then long() in Python 2.3

Peter Otten __peter__ at web.de
Tue Jul 13 10:31:33 EDT 2004


Willem wrote:

> When I run the follwing code using Python 2.3:
> 
> from time import clock
> t1 = clock ()
> for i in range (10000): a = int ('bbbbaaaa', 16)
> t2 = clock ()
> for i in range (10000): a = long ('bbbbaaaa', 16)
> t3 = clock ()
> print (t2-t1) / (t3-t2)
> 
> it prints out: 23.9673206147
> 
> That seems to mean that the int-conversion is 24 times slower than the
> long conversion.
> The reason is that in Python 2.3 the int-conversion generates
> warning messages that you *never* see but that consume a *lot* of CPU.

> I suppose that Python is getting over-engineered by too professional
> programmers. The first signs of decay?

No. I think warning.py needs some _more_ engineering - throw in a dictionary
to speed up repetetive calls or so. In the meantime:

import warnings
def dummy(*args, **kw):
    pass
warnings.warn = dummy

Now watch it speed up :)

Peter





More information about the Python-list mailing list