[JavaScript,PHP] スクリプト言語33 [Perl,Python]at TECH
[JavaScript,PHP] スクリプト言語33 [Perl,Python] - 暇つぶし2ch577:デフォルトの名無しさん
13/05/04 12:25:49.15
>>575
うっかりしてた。戻り値記述して再トライ

% cat fib2_py.pyx
cimport cython
cdef int fib(int n):
if n < 2: return n
return fib(n - 2) + fib(n - 1)
print(fib(38))

% cat setup2.py
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("fib2_py", ["fib2_py.pyx"])]
)

% python setup2.py build_ext --inplace
cythoning fib2_py.pyx to fib2_py.c
[...]

% time python -c 'import fib2_py'
39088169
python -c 'import fib2_py' 0.56s user 0.02s system 99% cpu 0.577 total

% cat fib2_py.c
[...]
__pyx_r = (__pyx_f_7fib2_py_fib((__pyx_v_n - 2)) + __pyx_f_7fib2_py_fib((__pyx_v_n - 1)));


次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch