에 line-profiler (ipython에서)를 사용했습니다.이 질문에 대한 답변을 How to profile cython functions line-by-line으로 읽었지만 설정이 제대로 작동하지 않습니다. 컴파일 된 Cython 코드
은 내가cumsum.pyx
파일이 : 나는하지 않는
%load_ext line_profiler
from cumsum import cumulative_sum
%lprun -f cumulative_sum cumulative_sum(100)
을 :
cython cumsum.pyx
gcc cumsum.c $(pkg-config --cflags --libs python3) -o cumsum.so -shared -fPIC
가 그럼 난 ipython
에 프로필을 시도 :
# cython: profile=True
# cython: linetrace=True
# cython: binding=True
DEF CYTHON_TRACE = 1
def cumulative_sum(int n):
cdef int s=0, i
for i in range(n):
s += i
return s
나는 그것을 컴파일 오류 메시지, 빈 프로필 만 :
Timer unit: 1e-06 s
Total time: 0 s
File: cumsum.pyx
Function: cumulative_sum at line 6
Line # Hits Time Per Hit % Time Line Contents
==============================================================
6 def cumulative_sum(int n):
7 cdef int s=0, i
8 for i in range(n):
9 s += i
10
11 return s
어떻게 작동합니까?
PS : 나는 CMake하지 setup.py
를 사용, 그래서 빌드 시스템을 무신론자 솔루션을 부탁드립니다
CYTHON_TRACE
매크로 설정하는 방법을 예를 포함
감사를 추가,
CMake와cumsum.pyx
4. 에 다음과 같습니다. 나는 그것을 시도했지만 문제를 해결하지 못합니다. – user357269
좀 더 구체적으로 설명해주십시오. 뭐가 문제 야? 'cythonize()'를 사용 했습니까? – MSeifert
아, 죄송합니다. 원래 게시물에서 변경된 사항이 없으면 프로필이 비어 있습니다. 당신이 그것을 "미리 컴파일"한다면 그것은 당신에게 효과가 있습니까? – user357269