Performance of int/long in Python 3

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Apr 7 04:29:19 EDT 2013


On Sat, 06 Apr 2013 19:58:02 -0600, Ian Kelly wrote:

> On Sat, Apr 6, 2013 at 7:29 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> For some definition of "easily".
>>
>> if implementation == "CPython":
>>     if version < "3.3":
>>         if sys.maxunicode exists:
>>             use it to decide whether this is a wide or narrow build if
>>             a wide build: return 4
>>             else: return 2
>>         else:
>>             ???
>>     elif version == "3.3":
>>         scan the string, in some efficient or inefficient way return 1,
>>         2, 4 depending on the largest character you find
>>     else:
>>         ???
>> else:
>>     ???
> 
> None of which goes away if a char width function is added to 3.4 and you
> still want to support earlier versions as this does.  It just adds
> another "if".

I grant you that for supporting earlier versions. But it will help with 
*future* versions. In principle, by Python 3.9, there could be six 
different checks just in the CPython section, to say nothing of PyPy, 
Jython, IronPython, and any other implementation.

An officially supported way of querying the kind of strings used will 
future-proof Python. In this regard, it's no different from (say) 
sys.float_info.



-- 
Steven



More information about the Python-list mailing list