def Factorial(int N):
cdef int checkSize = 5000
cdef int fi
cdef int endN
endN = N / checkSize
facResult = 1
for fi in range(1, endN + 1):
facResult = facResult * reduce(lambda x, y : x * y, range((fi-1)*checkSize+1,fi * checkSize+1))
if ( (endN * checkSize + 1) != (N+1) ):
facResult = facResult * reduce(lambda x, y : x * y, range(endN * checkSize + 1, N+1))
return facResult
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'Factorial app',
ext_modules = cythonize("factorial_100000.pyx"),
)
import time
from factorial_100000 import Factorial
startTime = time.time()
factorialN = Factorial(10000)
print "runtime is %s"%(time.time() - startTime)