The following Python runs unnecessarily slowly:
import fractions
fractions.Fraction(6249919, 6250000) ** 89993
The problem here is that Fraction.__pow__ constructs a new Fraction() to return, and Fraction.__new__ tries to gcd to normalize the numerator/denominator. The gcd is very, very slow, and more to the point, unnecessary; raising a normalized fraction to an integer power will always yield another normalized fraction.
fractions.Fraction.__pow__ should use this trick to make the code snippet above fast. |