Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
The situation for floats is also disappointing: $ python3.11 -m timeit -s 'x=1.1' 'x ** 2' 5000000 loops, best of 5: 60.8 nsec per loop $ python3.11 -m timeit -s 'x=1.1' 'x ** 2.0' 5000000 loops, best of 5: 51.5 nsec per loop $ python3.11 -m timeit -s 'x=1.1' 'x * x' 20000000 loops, best of 5: 17.7 nsec per loop Complex numbers are more balanced. Surprisingly, some of the complex cases are faster than their float counterparts: $ python3.11 -m timeit -s 'x=1.1+2.2j' 'x ** 2' 5000000 loops, best of 5: 42.4 nsec per loop $ python3.11 -m timeit -s 'x=1.1+2.2j' 'x ** 2.0' 5000000 loops, best of 5: 43.3 nsec per loop $ python3.11 -m timeit -s 'x=1.1+2.2j' 'x ** 2.0j' 2000000 loops, best of 5: 107 nsec per loop $ python3.11 -m timeit -s 'x=1.1+2.2j' 'x * x' 10000000 loops, best of 5: 30.6 nsec per loop Decimal still shows a large difference: $ python3.11 -m timeit -s 'from decimal import Decimal' -s 'x=Decimal("1.1")' 'x ** 2' 1000000 loops, best of 5: 206 nsec per loop $ python3.11 -m timeit -s 'from decimal import Decimal' -s 'x=Decimal("1.1")' 'x ** Decimal(2)' 1000000 loops, best of 5: 281 nsec per loop $ python3.11 -m timeit -s 'from decimal import Decimal' -s 'x=Decimal("1.1")' 'x * x' 5000000 loops, best of 5: 60.9 nsec per loop ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46020> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com