New submission from Cezary Wagner <cezary.wag...@gmail.com>:
I am experienced programmer 10y+ - that is very very strange performance problem when I play Python timeit with my son :) three way operator a <= x <= b is slower than a <= x and x <= b. It looks like wrong implementation since it is impossible that two separate check is faster that one check (with two low level check in C). import timeit REPEATS = 100 def test1(): selected = [] for i in range(REPEATS): if i >= 25 and i <= 75: selected.append(i) return selected def test2(): selected = [] for i in range(REPEATS): if 25 <= i <= 75: selected.append(i) return selected print(timeit.timeit(test1)) print(timeit.timeit(test2)) Result is on Windows 10. 4.428947699998389 4.9062477999978 ---------- components: Interpreter Core messages: 416699 nosy: Cezary.Wagner priority: normal severity: normal status: open title: Bug or bad performance type: performance versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue47221> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com