|
2089 | 2089 | <span class="hljs-number">0.34986</span>
|
2090 | 2090 | </code></pre></div>
|
2091 | 2091 |
|
2092 |
| -<div><h3 id="timingbyfunction">Timing by Function</h3><div><h4 id="generatesapngimageofacallgraphwithhighlightedbottlenecks">Generates a PNG image of a call graph with highlighted bottlenecks:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pycallgraph</span> |
2093 |
| -<span class="hljs-keyword">from</span> pycallgraph <span class="hljs-keyword">import</span> output, PyCallGraph |
2094 |
| -<span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime |
2095 |
| -time_str = datetime.now().strftime(<span class="hljs-string">'%Y%m%d%H%M%S'</span>) |
2096 |
| -filename = <span class="hljs-string">f'profile-<span class="hljs-subst">{time_str}</span>.png'</span> |
2097 |
| -drawer = output.GraphvizOutput(output_file=filename) |
2098 |
| -<span class="hljs-keyword">with</span> PyCallGraph(drawer): |
2099 |
| - <code_to_be_profiled> |
2100 |
| -</code></pre></div></div> |
2101 |
| - |
2102 |
| - |
2103 |
| -<div><h3 id="profilingbyline">Profiling by Line</h3><pre><code class="text language-text">$ pip3 install line_profiler memory_profiler |
| 2092 | +<div><h3 id="profilingbyline">Profiling by Line</h3><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install line_profiler memory_profiler</span> |
| 2093 | +<span class="hljs-meta">@profile</span> |
| 2094 | +<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span> |
| 2095 | + a = [*range(<span class="hljs-number">10000</span>)] |
| 2096 | + b = {*range(<span class="hljs-number">10000</span>)} |
| 2097 | +main() |
2104 | 2098 | </code></pre></div>
|
2105 | 2099 |
|
2106 | 2100 | <pre><code class="text language-text">$ kernprof -lv test.py
|
|
2119 | 2113 | 3 35.734 MiB 0.348 MiB a = [*range(10000)]
|
2120 | 2114 | 4 36.160 MiB 0.426 MiB b = {*range(10000)}
|
2121 | 2115 | </code></pre>
|
| 2116 | +<div><h3 id="callgraph">Call Graph</h3><div><h4 id="generatesapngimageofacallgraphwithhighlightedbottlenecks">Generates a PNG image of a call graph with highlighted bottlenecks:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install pycallgraph</span> |
| 2117 | +<span class="hljs-keyword">from</span> pycallgraph <span class="hljs-keyword">import</span> output, PyCallGraph |
| 2118 | +<span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime |
| 2119 | +time_str = datetime.now().strftime(<span class="hljs-string">'%Y%m%d%H%M%S'</span>) |
| 2120 | +filename = <span class="hljs-string">f'profile-<span class="hljs-subst">{time_str}</span>.png'</span> |
| 2121 | +drawer = output.GraphvizOutput(output_file=filename) |
| 2122 | +<span class="hljs-keyword">with</span> PyCallGraph(drawer): |
| 2123 | + <code_to_be_profiled> |
| 2124 | +</code></pre></div></div> |
| 2125 | + |
| 2126 | + |
2122 | 2127 | <div><h2 id="numpy"><a href="#numpy" name="numpy">#</a>NumPy</h2><p><strong>Array manipulation mini language. Can run up to one hundred times faster than equivalent Python code.</strong></p><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install numpy</span>
|
2123 | 2128 | <span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
|
2124 | 2129 | </code></pre></div>
|
|
0 commit comments