Message349789
Recording before I forget. These are easy:
1. As the comments note, cache the hash code.
2. Use the new (in 3.8) pow(denominator, -1, modulus) to get the inverse instead of raising to the modulus-2 power. Should be significantly faster. If not, the new "-1" implementation should be changed ;-) Will require catching ValueError in case the denom is a multiple of the modulus.
3. Instead of multiplying by the absolute value of the numerator, multiply by the hash of the absolute value of the numerator. That changes the multiplication, and the subsequent modulus operation, from unbounded-length operations to short bounded-length ones. Hashing the numerator on its own should be significantly faster, because the int hash doesn't require any multiplies or divides regardless of how large the numerator is.
None of those should change any computed results. |
|
Date |
User |
Action |
Args |
2019-08-15 02:30:45 | tim.peters | set | recipients:
+ tim.peters |
2019-08-15 02:30:45 | tim.peters | set | messageid: <1565836245.18.0.379877186731.issue37863@roundup.psfhosted.org> |
2019-08-15 02:30:45 | tim.peters | link | issue37863 messages |
2019-08-15 02:30:44 | tim.peters | create | |
|