[issue45542] Using multiple comparison operators can cause performance issues

2022-04-07 Thread Brandt Bucher
Change by Brandt Bucher : -- nosy: +brandtbucher ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue45542] Using multiple comparison operators can cause performance issues

2022-04-04 Thread Dennis Sweeney
Dennis Sweeney added the comment: For reference, chaining is about 1.18x slower in this microbenchmark on GCC: ./python -m pyperf timeit -s "x = 100" "if 10 < x < 30: print('no')" --duplicate=10 . Mean +- std dev: 21.3 ns +- 0.2 ns ./python -m pyperf timeit -s "x = 100" "i

[issue45542] Using multiple comparison operators can cause performance issues

2022-04-04 Thread Steven D'Aprano
Steven D'Aprano added the comment: I came here from #47221. If I am reading this correctly, it concerns me that stack operations (which should be fast) are apparently slow? If we can't reduce the number of stack operations, can we speed them up? -- nosy: +steven.daprano status: pend

[issue45542] Using multiple comparison operators can cause performance issues

2022-04-04 Thread Dennis Sweeney
Dennis Sweeney added the comment: https://bugs.python.org/issue47221 was opened as a duplicate of this. Unless there are any new ideas for getting around the concerns here, I think this can be closed. -- status: open -> pending ___ Python tracker

[issue45542] Using multiple comparison operators can cause performance issues

2021-10-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Agree with Tim. The idea of optimizing stack manipulation operations for constants is interesting, but is it common enough case to justify the compiler complication? See also rejected issue27236. -- nosy: +serhiy.storchaka ___

[issue45542] Using multiple comparison operators can cause performance issues

2021-10-20 Thread Tim Peters
Tim Peters added the comment: I think Dennis's example is fatal: from section 6.10 ("Comparisons"): """ Comparisons can be chained arbitrarily, e.g., `x < y <= z` is equivalent to `x < y and y <= z`, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y

[issue45542] Using multiple comparison operators can cause performance issues

2021-10-20 Thread Dennis Sweeney
Dennis Sweeney added the comment: The PR changes behavior slightly: def f(): class A: def __lt__(self, other): nonlocal x x += 100 return True a = A() x = 1 print(a < x < 10) x = 1 print(a < x and x < 10) ### Before ### >>> f

[issue45542] Using multiple comparison operators can cause performance issues

2021-10-20 Thread Maja
Change by Maja : -- keywords: +patch pull_requests: +27377 stage: -> patch review pull_request: https://github.com/python/cpython/pull/29109 ___ Python tracker ___ ___

[issue45542] Using multiple comparison operators can cause performance issues

2021-10-20 Thread Maja
New submission from Maja : For example: def f(x): return 1 < x < 3 will be slower than: def f(x): return 1 < x and x < 3 The first function will generate following bytecode: 0 LOAD_CONST 1 (1) 2 LOAD_FAST0 (x)