私はPythonコードをCに移植しようとしていますが、その前に私は性能テストを行いましたが、性能が向上していないようです。Cythonのパフォーマンステスト
まずCプログラム:
#include <stdio.h>
main()
{
printf("hello world \n");
}
[[email protected] c]$ gcc test.c
[[email protected] c]$ time ./a.out
hello world
real 0m0.001s
user 0m0.000s
sys 0m0.000s
セカンドPythonプログラム:cythonはしなかったようCythonサード
#!/usr/bin/env python
print "hello world \n"
[[email protected] c]$ time python test.py
hello world
real 0m0.024s
user 0m0.020s
sys 0m0.003s
...
test.py
print "hello world \n"
[[email protected] c]$ cython --embed test.py
[[email protected] c]$ gcc $CFLAGS -I/usr/include/python2.6 -o test test.c -lpython2.6 -lpthread -lm -lutil -ldl
[[email protected] c]$ time ./test
hello world
real 0m0.024s
user 0m0.019s
sys 0m0.004s
だから私にはそれが見えますすべてのパフォーマンスを向上させます。なぜ、どのように私はcythonとしてこれを修正することができます任意のアイデアは、Pythonコードをより速く実行させることになっていますか?
Cythonはバイトコードのディスパッチオーバーヘッドを削除し、静的型の注釈でヒントを付けるとPythonオブジェクトを削除することがあります。すべてのPythonコードを魔法のように 'libc'呼び出しにコンパイルすることはできませんし、インタプリタのC APIを呼び出すことなくほとんどのPythonのセマンティクスを実装することはできません。 10億の整数を追加するループを比較してみてください。 – delnan