问题标签 [line-profiler]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
268 浏览

python - Python line profiler 结果不一致

为什么尽管相同的代码运行两次,python 代码的运行速度却截然不同?

代码

我正在为一个简短的 Python 代码做一些分析:

测试

我正在使用line_profiler命令kernprof -l -v test.py。我多次测试了这段代码,所有结果都不一致。

测试1:

测试 2(我编辑了代码):

测试 3:

这是我感到困惑的部分。最初需要 44 秒运行的进程现在需要 4 秒才能运行。我还注意到,每当我编辑文件时,再次运行都需要很长时间。这里有另外三个测试证明我的观点:

编辑后的第一次测试:

编辑后的第二次测试:

编辑后的第三次测试(类似于第二次测试):

0 投票
2 回答
2041 浏览

python - 从 pip 和 repro 安装 line_profiler 和 kernprof 不起作用

我已经尝试了建议的内容。在最简单的代码上,我得到了其他人提到的熟悉的错误。错误是:

在最小的代码上:

从命令行:

我已经导入future,甚至从我的 virtualenv 之外的发行版安装。这是之前的建议,就像导入未来的模块一样。

所以

也给出了同样的错误。我无法让这个 line profiler 与 pip 一起使用,甚至无法从原始存储库中使用。我的版本是:

0 投票
1 回答
1277 浏览

python - 找不到 kernprof 命令 - Ubuntu

我刚刚在 Ubuntu 上使用 pip 安装了 line_profiler。我关闭并重新打开终端,cd 到包含我的文件的目录,然后运行 ​​kernprof。Bash 告诉我它找不到kernprof。巧合的是,我只是在 windows 上做了完全相同的过程,它工作得很好。

编辑:所以 pip 实际上并没有安装它,或者将 kernprof 放在错误的目录中。从 pypi 下载 tarball 并运行安装程序。

0 投票
0 回答
247 浏览

python - 如何将 python line_profiler 与 uwsgi 一起使用?

通常我会使用@profile装饰器并使用kernprof -l. 我如何为通过 uwsgi 服务器执行的代码执行此操作?

看起来您可以通过 line profiler api: 添加要分析的函数LineProfiler(my_fun)。也许这会奏效?我如何将结果转储到文件中?

0 投票
1 回答
3216 浏览

python - Python line_profiler 找不到模块

我认识到这是我的安装失败,很抱歉将这个无趣且无关紧要的问题放在你的脚下,但对于我的生活,我无法弄清楚出了什么问题,我已经没有想法。我希望有人能够迅速指出显而易见的事情。

我正在尝试分析一个 python 脚本(使用 Kern 的 line_profiler),并且该脚本需要加载 netCDF4 模块。我已经用 pip 安装了 line_profiler 和 netCDF4。当我为已安装软件包列表排队 pip 时,两者都报告为存在并更新。

在不使用分析器的情况下,我的脚本运行没有问题,这意味着 netCDF4 模块已正确加载。但是,如果我从“myscript”目录运行“kernprof -l -v myscript.py”,我会收到以下错误:

我从 /opt/local/bin/python 的安装中运行 Python,它在我的 PATH 中首先列出。

所以,无论如何,如果我设置的默认 Python 版本与我的 PATH 中最先出现的版本相同,并且该默认版本能够访问 netCDF4 模块,为什么 line_profiler 不是呢?

0 投票
2 回答
938 浏览

python - 在编译的 Cython 代码上使用 line-profiler(在 ipython 中)

我阅读了这个问题的答案How to profile cython functions line-by-line,但我似乎无法让它与我的设置一起使用。

我有一个cumsum.pyx文件:

我编译它:

然后我尝试将其描述为ipython

我没有收到错误消息,只有一个空的个人资料:

我怎样才能让它工作?

PS:我使用 CMake,而不是setup.py,所以我会很感激构建系统不可知的解决方案

0 投票
0 回答
814 浏览

python - python line_profiler(kernprof)不适用于最小示例

这是我的script.py

我安装了line_profiler

并按如下方式运行

这很奇怪......没有按行计时的结果!

所以我查看了转储,但也没有运气:

任何想法我如何错误地使用这个库?

0 投票
0 回答
288 浏览

python - line profiling Cython 0.25

I am trying to line profile some code I wrote in Cython. But I cannot get it to work.

I have tried to follow all the steps given in How to profile cython functions line-by-line

But I dont get any timings out as a result. What I done is posted here:

I am using python 3.6 and Cython 0.25.2

What I try to do:

First I run:

In setup.py I have added:

and to the extension I added,

In the script runMIcython.pyx, I have added:

In an ipython shell, I then try to run (takes about 1 min):

But the output I get is:

0 投票
1 回答
744 浏览

python - 无法将 line_profiler 与 Cython 一起使用

根据对这个问题的回答,我试图将line_profiler与 cythonized 函数一起使用。

在上述问题上,接受的答案为我们提供了如何将它与 jupyter notebook 一起使用的示例。

但是,当我尝试pyx使用 disutils 构建文件时,它不起作用。

我们我明确地尝试使用运行脚本

它只返回Timer unit经过的时间。

如果我尝试使用 修饰 cython 文件上的函数@profile,它不会编译返回:

有任何想法吗 ?

0 投票
0 回答
190 浏览

python - line_profiler 安装失败:UnicodeDecodeError

尝试通过安装 line_profiler pip install line_profiler,我不断收到相同的错误:

注意:我手动添加cl.exe到 PATH 变量中,因为我无法开始vcvarsall.bat x64工作。

关于如何解决这个问题的任何想法?我正在使用 python 3.6:line_profiler 是否仅适用于 python 2.X?