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

James Henderson james at logicalprogression.net
Tue Jul 13 18:32:29 CEST 2004


On Tuesday 13 July 2004 3:09 pm, 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.
>
> So it may happen that old code performing well under Python 2.2 suddenly
> slows down a considerable amount under Python 2.3 without any percievable
> change in the output ...

I don't think this code did work perfectly well under Python2.2 (see below), 
or am I missing something?

Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range (10000): a = int ('bbbbaaaa', 16)
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: int() literal too large: bbbbaaaa
>>>

-- 
James Henderson, Logical Progression Ltd
http://www.logicalprogression.net
http://mailmanager.sourceforge.net




More information about the Python-list mailing list