Message408076
The expression 'x * x' is faster than 'x ** 2'.
In Python3.10, the speed difference was enormous. Due to ceval optimizations, the difference in Python3.11 is tighter; however, there is still room for improvement.
The code for long_pow() doesn't currently have a fast path for squaring which is by far the most important case.
$ python3.10 -m timeit -r 11 -s 'x = 10' 'x ** 2'
1000000 loops, best of 11: 201 nsec per loop
$ python3.10 -m timeit -r 11 -s 'x = 10' 'x * x'
10000000 loops, best of 11: 21.9 nsec per loop
$ python3.11 -m timeit -r 11 -s 'x = 10' 'x ** 2'
10000000 loops, best of 11: 32 nsec per loop
$ python3.11 -m timeit -r 11 -s 'x = 10' 'x * x'
20000000 loops, best of 11: 17.6 nsec per loop |
|
Date |
User |
Action |
Args |
2021-12-09 06:32:23 | rhettinger | set | recipients:
+ rhettinger |
2021-12-09 06:32:23 | rhettinger | set | messageid: <1639031543.32.0.0830001202943.issue46020@roundup.psfhosted.org> |
2021-12-09 06:32:23 | rhettinger | link | issue46020 messages |
2021-12-09 06:32:23 | rhettinger | create | |
|