On 11/28/2021 7:52 PM, Christopher Barker wrote:
I will frequently do simple computation with literals to make my code more clear:

t = 2 * 3600  # 2 hours in seconds

That is optimized as you'd hope. Tested in 3.8:

>>> dis.dis("t = 2 * 3600")
  1           0 LOAD_CONST               0 (7200)
              2 STORE_NAME               0 (t)
              4 LOAD_CONST               1 (None)
              6 RETURN_VALUE

Eric


But I see no need to optimize this kind of thing -- it would never be in a tight loop.

-CHB


On Sun, Nov 28, 2021 at 3:06 PM Rob Cliffe via Python-Dev <python-dev@python.org> wrote:

    I am slightly surprised that it seems to be *easier* to fold selected
    constant expressions than to have more generic code to fold them all.
    Or at least, all those that don't contain containers, such as
         1 in [0,1,2]
    Rob Cliffe

    On 28/11/2021 21:10, Eric V. Smith wrote:
    >> On Nov 28, 2021, at 3:03 PM, Serhiy Storchaka
    <storch...@gmail.com> wrote:
    >>
    >> 28.11.21 17:13, Skip Montanaro пише:
    >>>> That is not entirely true:
    https://github.com/python/cpython/pull/29639#issuecomment-974146979
    >>> The only places I've seen "if 0:" or "if False:" in live code
    was for
    >>> debugging. Optimizing that hardly seems necessary. In any
    case, the
    >>> original comment was about comparisons of two constants. I suppose
    >>> sweeping up all of that into a constant expression
    folding/elimination
    >>> step performed on the AST and/or during peephole optimization
    would
    >>> cover both cases.
    >> "if 0:" and "if False:" is already optimized by the compiler.
    The OP
    >> proposes to optimize "2 < 1", and I cannot imagine any use case
    for this.
    > I agree. I suggest we don’t add this optimization.
    >
    > Eric
    > _______________________________________________
    > Python-Dev mailing list -- python-dev@python.org
    > To unsubscribe send an email to python-dev-le...@python.org
    > https://mail.python.org/mailman3/lists/python-dev.python.org/
    > Message archived at
    
https://mail.python.org/archives/list/python-dev@python.org/message/JP6FF2RHDQSIOS6ZAI45S7X6UXWGPBKR/
    > Code of Conduct: http://python.org/psf/codeofconduct/

    _______________________________________________
    Python-Dev mailing list -- python-dev@python.org
    To unsubscribe send an email to python-dev-le...@python.org
    https://mail.python.org/mailman3/lists/python-dev.python.org/
    Message archived at
    
https://mail.python.org/archives/list/python-dev@python.org/message/LD3XHINO7VPDE5EMNFD5ON4FQIJLY4DI/
    Code of Conduct: http://python.org/psf/codeofconduct/



--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython

_______________________________________________
Python-Dev mailing list --python-dev@python.org
To unsubscribe send an email topython-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived 
athttps://mail.python.org/archives/list/python-dev@python.org/message/NJWCKNV4ULEBHSLR44G3HNVROE4IAM47/
Code of Conduct:http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/YEG3B44GJRHACEB4U6U2VAHT5E2SVXTO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to