from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext setup( cmdclass = {'build_ext': build_ext}, ext_modules = [Extension("number_theory", ["number_theory.pyx"])] )
一個例牌setup.py,然後:
$ python3.2 setup.py build_ext --inplace $ python3.2 -m timeit -n 10 -s 'import number_theory' 'number_theory.primitive_root(2616139)' 10 loops, best of 3: 377 msec per loop
和PyPy相比,速度沒有優勢,但support Python 3。跟著改source,加Type declaration試試,
cdef int i, p, a, i2 for i in range(2, p):
$ python3.2 -m timeit -n 10 -s 'import number_theory' 'number_theory.primitive_root(2616139)' 10 loops, best of 3: 262 msec per loop
速度分別不大,而且並不適用,因為會Overflow。
沒有留言:
發佈留言