On Tue, Oct 12, 2021 at 10:41 PM Jeremiah Vivian
<nohackingofkrow...@gmail.com> wrote:
>
> 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?
>

-1. It's unnecessary optimization for an uncommon case, abuse of
syntax (it's even worse than JavaScript using +"123" to force it to be
a number), and illogical - why should +"a" be the integer 97?

ChrisA
_______________________________________________
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/Y3YSNBXDMNGR6SSSIVRSLET3ZIR6EZYK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to