Ped*_*raz 6 python cython line-profiler
基于对答案这个问题,我试图用line_profiler用cythonized功能.
在上述问题上,接受的答案为我们提供了一个如何在jupyter笔记本中使用它的例子.
但是,当我尝试pyx使用disutils 构建文件时,它不起作用.
我明确地尝试使用脚本来运行
kernprof -l -v script.py
Run Code Online (Sandbox Code Playgroud)
它只返回Timer unit经过的时间.
如果我尝试使用cython文件修饰函数@profile,它不会编译返回:
undeclared name not builtin: profile
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
该profile装饰注入globals的命名空间kernprof,因此无法在编译时。但是,即使在定义函数之后,您也可以将profile装饰器应用于函数。例如,script.py您可以在其中编写以下内容。
from cython_module import function_to_be_profiled
# Apply the `profile` decorator
function_to_be_profiled = profile(function_to_be_profiled)
# Use function_to_be_profiled as intended
Run Code Online (Sandbox Code Playgroud)
如果您使用标准 python 运行脚本,则代码段的第三行将失败,即python script.py,因为profile未定义装饰器。但是,如果您使用kernprof.