2024-10-04 05:20:37 发布
网友
基于对this question的回答,我试图将line_profiler与cythoized函数一起使用。在
关于上述问题,公认的答案给了我们一个例子,说明如何使用它与jupyter笔记本电脑。在
但是,当我试图使用diustils构建pyx文件时,它不起作用。在
pyx
我们很明显地尝试使用
kernprof -l -v script.py
它只返回Timer unit经过的时间。在
Timer unit
如果我试图用@profile修饰cython文件上的函数,它不会编译返回:
@profile
有什么想法吗?在
profile修饰符由kernprof注入到globals命名空间中,因此在编译时不可用。但是,您可以apply the ^{} decorator to a function even after it has been defined。例如,在您的script.py中,您可以编写以下内容。在
profile
kernprof
globals
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
如果使用标准python运行脚本,即python script.py,则代码段的第三行将失败,因为没有定义profile修饰符。但是如果您使用kernprof运行它,它的行为应该与预期的一样。在
python script.py
profile
修饰符由kernprof
注入到globals
命名空间中,因此在编译时不可用。但是,您可以apply the ^{script.py
中,您可以编写以下内容。在如果使用标准python运行脚本,即
python script.py
,则代码段的第三行将失败,因为没有定义profile
修饰符。但是如果您使用kernprof
运行它,它的行为应该与预期的一样。在相关问题 更多 >
编程相关推荐