gpt4 book ai didi

python - 如何分析 cdef 函数?

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:23 26 4
gpt4 key购买 nike

我有一个使用许多 nogil cdef 函数的应用程序,我想对它们进行分析为了找到瓶颈。

我尝试将 profile=True 指令传递给 Cython,但这些函数似乎是免疫的,因此 cProfile.run() 的输出包含函数调用 cdef 函数,但不是 cdef 函数本身。

是否有其他指令或分析器可用于分析 cdef 函数?


编辑:this is link to the application file that I am referring to... .为了配置文件,您必须设置:

#cython: profile=True

在标题处。

最佳答案

探查器需要gil,因此,借助@Veedrac 的评论,解决方案是:

  • 仅使用 cdef 函数而不使用 nogil 指令
  • .pyx ( or somewhere else ) 的 header 设置 #cython: profile=True

这里的缺点是,通过删除 nogil,不能使用 prange 来分析并行执行。另一个问题仍然存在……是否可以分析 nogil 函数?

关于python - 如何分析 cdef 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23063047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com