<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Profile on Sawyer Zheng's Blog</title><link>https://elated-raman-42e0c2.netlify.app/tags/profile/</link><description>Recent content in Profile on Sawyer Zheng's Blog</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Thu, 26 May 2022 18:44:41 +0800</lastBuildDate><atom:link href="https://elated-raman-42e0c2.netlify.app/tags/profile/index.xml" rel="self" type="application/rss+xml"/><item><title>Python Memory Profile Notes</title><link>https://elated-raman-42e0c2.netlify.app/post/notes/python/memory_profile/</link><pubDate>Tue, 29 Jun 2021 00:00:00 +0000</pubDate><guid>https://elated-raman-42e0c2.netlify.app/post/notes/python/memory_profile/</guid><description>&lt;div id="outline-container-headline-1" class="outline-2"&gt;
&lt;h2 id="headline-1"&gt;
工具
&lt;/h2&gt;
&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://docs.python.org/3/library/tracemalloc.html"&gt;tracemalloc&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;内存分配跟踪 trace memory allocations&lt;/li&gt;
&lt;li&gt;官方库&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pythonprofilers/memory_profiler"&gt;memory_profiler&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://pypi.org/project/line-profiler/"&gt;line-profiler&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;逐行 profile&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-2" class="outline-2"&gt;
&lt;h2 id="headline-2"&gt;
line-profiler
&lt;/h2&gt;
&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;命令行使用&lt;/p&gt;
&lt;div class="src src-sh"&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 第一步 ---&amp;gt; 生成 profile 结果文件 --&amp;gt; your_script.py.lprof&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;kernprof -l -v your_script.py
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# 第二步 ---&amp;gt; 格式化展示&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;python -m line_profiler your_script.py.lprof&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;例子&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;注意：不需要导入 profile 装饰器&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/danriti/8015889"&gt;Line Profiling in Python · GitHub&lt;/a&gt;&lt;/p&gt;</description></item><item><title>profile ---- python time consuming Python 运行时间分析工具</title><link>https://elated-raman-42e0c2.netlify.app/post/notes/python/profile/</link><pubDate>Fri, 11 Jun 2021 00:00:00 +0000</pubDate><guid>https://elated-raman-42e0c2.netlify.app/post/notes/python/profile/</guid><description>&lt;div id="outline-container-headline-1" class="outline-2"&gt;
&lt;h2 id="headline-1"&gt;
工具
&lt;/h2&gt;
&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;
&lt;ul&gt;
&lt;li&gt;graphviz&lt;/li&gt;
&lt;li&gt;snakeviz&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@narenandu/profiling-and-visualization-tools-in-python-89a46f578989"&gt;gprof2dot&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-2" class="outline-2"&gt;
&lt;h2 id="headline-2"&gt;
profiler
&lt;/h2&gt;
&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;
&lt;ul&gt;
&lt;li&gt;cProfile&lt;/li&gt;
&lt;li&gt;profile&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-3" class="outline-2"&gt;
&lt;h2 id="headline-3"&gt;
使用
&lt;/h2&gt;
&lt;div id="outline-text-headline-3" class="outline-text-2"&gt;
&lt;div id="outline-container-headline-4" class="outline-3"&gt;
&lt;h3 id="headline-4"&gt;
snakeviz
&lt;/h3&gt;
&lt;div id="outline-text-headline-4" class="outline-text-3"&gt;
&lt;div class="src src-sh"&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;python -m cProfile -o /to/profile_result.prof your_program.py args
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;snakeviz /to/profile.prof&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;结果&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;网站&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-5" class="outline-3"&gt;
&lt;h3 id="headline-5"&gt;
gprof2dot
&lt;/h3&gt;
&lt;div id="outline-text-headline-5" class="outline-text-3"&gt;
&lt;div class="src src-sh"&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;python -m cProfile -o profile.pstats program.py args
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;gprof2doc -f pstats /to/profile.pstats &lt;span class="p"&gt;|&lt;/span&gt; dot -Tpng -o result.png&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;结果&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;函数调用图片&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-6" class="outline-2"&gt;
&lt;h2 id="headline-6"&gt;
代码速度
&lt;/h2&gt;
&lt;div id="outline-text-headline-6" class="outline-text-2"&gt;
&lt;div id="outline-container-headline-7" class="outline-3"&gt;
&lt;h3 id="headline-7"&gt;
set 快于 list
&lt;/h3&gt;
&lt;div id="outline-text-headline-7" class="outline-text-3"&gt;
&lt;p&gt;x in set 快于 x in list&lt;/p&gt;</description></item></channel></rss>