파이썬 코드를 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
두 번째 파이썬 프로그램 : 사이 썬하지 않았다처럼 사이 썬 셋째
#!/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으로 이것을 고칠 수있는 아이디어가 있으면 파이썬 코드를 더 빠르게 실행할 수 있습니까?
Cython은 바이트 코드 디스패치 오버 헤드를 제거하고 정적 유형 주석으로 힌트를 제공하면 Python 객체를 제거 할 수 있습니다. 모든 파이썬 코드를 마술처럼'libc' 호출로 컴파일 할 수는 없으며 인터프리터의 C API를 호출하지 않고 대부분의 파이썬 의미를 구현할 수 없습니다. 10 억 개의 정수를 추가하는 루프를 비교해보십시오. – delnan