[JavaScript,PHP] スクリプト言語33 [Perl,Python]at TECH[JavaScript,PHP] スクリプト言語33 [Perl,Python] - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト573:デフォルトの名無しさん 13/05/04 12:01:45.29 うちでもやってみた。Cython の使い方間違ってたら指摘してくれると助かる % cat fib_c.c #include <stdio.h> int fib(int n) { if (n < 2) return n; return fib(n - 1) + fib(n - 2); } int main(void) { printf("%d\n", fib(38)); return 0; } % gcc -o fib_c fib_c.c % time ./fib_c 39088169 ./fib_c 1.12s user 0.00s system 99% cpu 1.125 total つづく 574:デフォルトの名無しさん 13/05/04 12:03:22.85 つづき % cat fib_py.pyx cimport cython cdef fib(int n): if n < 2: return n return fib(n - 2) + fib(n - 1) print(fib(38)) % cat setup.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("fib_py", ["fib_py.pyx"])] ) % python setup.py build_ext --inplace [...] % time python -c "import fib_py" 39088169 python -c "import fib_py" 3.87s user 0.01s system 99% cpu 3.894 total 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch