So `ord` is already a really fast function with (last check before this thread 
was posted) 166 nsec per loop. But I'm wondering... doing `ord(a)` produces 
this bytecode:
>  2           4 LOAD_NAME                1 (ord)
>              6 LOAD_NAME                0 (a)
>              8 CALL_FUNCTION            1
>             10 POP_TOP
>             12 LOAD_CONST               1 (None)
>             14 RETURN_VALUE
But doing `+a` only produces this:
>  2           4 LOAD_NAME                0 (a)
>              6 UNARY_POSITIVE
>              8 POP_TOP
>             10 LOAD_CONST               1 (None)
>             12 RETURN_VALUE
So an operator has its own bytecode, doesn't need to `LOAD_*` a function, and 
doesn't have the impact on performance when converting arguments to the format 
of the (after `POP()`ing every argument) TOS function and then calling that 
function. And also, the unary `+` of strings only copies strings, which should 
be redundant in most cases. Maybe `ord` can take the place of unary `+` in 
strings?
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6M235Y3WDVRNOPHAY4JKKRIZNKMIGBMD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to