[issue22477] GCD in Fractions

gladman report at bugs.python.org
Wed Oct 8 10:14:04 CEST 2014


gladman added the comment:

You might be right that it is not worth adding the ability to handle a variable number of parameters in the new gcd.  But this depends on whether you are right that this would add a significant burden to the implementation.  I am not sure that it would.

But for pure Python implementations of gcd and gcdm:

def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

def gcdm(a, *r):
  for b in r:
    while b:
      a, b = b, a % b
  return a

using the second of these alone when compared with the first plus reduce on a 10000 length sequence of random numbers in 0 <= r < 10 ** 12 gives speed improvement of over 25%.  

And, since we are looking for speed improvements, a further possible 25% is a worthwhile gain for a common pattern of gcd use.  Which is why I believe it is worth asking the question.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22477>
_______________________________________


More information about the Python-bugs-list mailing list