[docs] Python faster factorial implementation

Jason jason at jason.gd
Sat May 19 18:49:16 CEST 2012


Hello. I'd like you to change python math module factorial implementation.

For numbers like 100 000 my implementation is pretty much faster:

def fact( a, b ):
     c=0
     if b == a: return a
     if b-a > 1:
         c=(b + a) >> 1;
         return (fact(a, c) * fact(c+1, b))
     return a * b
fact(1,100000)

duration: 0:00:00.293773


If you use:

import math
math.factorial(100000)

the duration is: 0:00:04.022968 !!!

Is it possible or it's too much effort for Python developers?

I'm looking forward for your reply ;)

Regards,
     Jason.


More information about the docs mailing list