Skip to content

Commit 606208a

Browse files
committed
Web, Profiling
1 parent cab4568 commit 606208a

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

Diff for: README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ def send_page(sport):
24962496

24972497
### REST Request
24982498
```python
2499-
@post('/odds/<sport>')
2499+
@post('/<sport>/odds')
25002500
def odds_handler(sport):
25012501
team = request.forms.get('team')
25022502
home_odds, away_odds = 2.44, 3.29
@@ -2510,7 +2510,7 @@ def odds_handler(sport):
25102510
# $ pip3 install requests
25112511
>>> import threading, requests
25122512
>>> threading.Thread(target=run, daemon=True).start()
2513-
>>> url = 'http://localhost:8080/odds/football'
2513+
>>> url = 'http://localhost:8080/football/odds'
25142514
>>> data = {'team': 'arsenal f.c.'}
25152515
>>> response = requests.post(url, data=data)
25162516
>>> response.json()
@@ -2577,11 +2577,10 @@ Line # Mem usage Increment Line Contents
25772577
### Call Graph
25782578
#### Generates a PNG image of a call graph with highlighted bottlenecks:
25792579
```python
2580-
# $ pip3 install pycallgraph
2581-
from pycallgraph import output, PyCallGraph
2580+
# $ pip3 install pycallgraph2
2581+
from pycallgraph2 import output, PyCallGraph
25822582
from datetime import datetime
2583-
time_str = datetime.now().strftime('%Y%m%d%H%M%S')
2584-
filename = f'profile-{time_str}.png'
2583+
filename = f'profile-{datetime.now():%Y%m%d%H%M%S}.png'
25852584
drawer = output.GraphvizOutput(output_file=filename)
25862585
with PyCallGraph(drawer):
25872586
<code_to_be_profiled>
@@ -2961,14 +2960,14 @@ while all(event.type != pg.QUIT for event in pg.event.get()):
29612960
```
29622961

29632962
```python
2964-
from pygame.transform import scale,
2963+
from pygame.transform import scale, ...
29652964
<Surf> = scale(<Surf>, (width, height)) # Returns scaled surface.
29662965
<Surf> = rotate(<Surf>, degrees) # Returns rotated and scaled surface.
29672966
<Surf> = flip(<Surf>, x_bool, y_bool) # Returns flipped surface.
29682967
```
29692968

29702969
```python
2971-
from pygame.draw import line,
2970+
from pygame.draw import line, ...
29722971
line(<Surf>, color, (x1, y1), (x2, y2), width) # Draws a line to the surface.
29732972
arc(<Surf>, color, <Rect>, from_rad, to_rad) # Also: ellipse(<Surf>, color, <Rect>)
29742973
rect(<Surf>, color, <Rect>) # Also: polygon(<Surf>, color, points)

Diff for: index.html

+7-8
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@
21842184
<span class="hljs-keyword">return</span> template(<span class="hljs-string">'&lt;h1&gt;{{title}}&lt;/h1&gt;'</span>, title=sport)
21852185
</code></pre></div>
21862186

2187-
<div><h3 id="restrequest">REST Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@post('/odds/&lt;sport&gt;')</span>
2187+
<div><h3 id="restrequest">REST Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@post('/&lt;sport&gt;/odds')</span>
21882188
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">odds_handler</span><span class="hljs-params">(sport)</span>:</span>
21892189
team = request.forms.get(<span class="hljs-string">'team'</span>)
21902190
home_odds, away_odds = <span class="hljs-number">2.44</span>, <span class="hljs-number">3.29</span>
@@ -2196,7 +2196,7 @@
21962196
<div><h4 id="test">Test:</h4><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install requests</span>
21972197
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> threading, requests
21982198
<span class="hljs-meta">&gt;&gt;&gt; </span>threading.Thread(target=run, daemon=<span class="hljs-keyword">True</span>).start()
2199-
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">'http://localhost:8080/odds/football'</span>
2199+
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">'http://localhost:8080/football/odds'</span>
22002200
<span class="hljs-meta">&gt;&gt;&gt; </span>data = {<span class="hljs-string">'team'</span>: <span class="hljs-string">'arsenal f.c.'</span>}
22012201
<span class="hljs-meta">&gt;&gt;&gt; </span>response = requests.post(url, data=data)
22022202
<span class="hljs-meta">&gt;&gt;&gt; </span>response.json()
@@ -2246,11 +2246,10 @@
22462246
3 38.012 MiB 0.344 MiB a = [*range(10000)]
22472247
4 38.477 MiB 0.465 MiB b = {*range(10000)}
22482248
</code></pre>
2249-
<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>
2250-
<span class="hljs-keyword">from</span> pycallgraph <span class="hljs-keyword">import</span> output, PyCallGraph
2249+
<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 pycallgraph2</span>
2250+
<span class="hljs-keyword">from</span> pycallgraph2 <span class="hljs-keyword">import</span> output, PyCallGraph
22512251
<span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime
2252-
time_str = datetime.now().strftime(<span class="hljs-string">'%Y%m%d%H%M%S'</span>)
2253-
filename = <span class="hljs-string">f'profile-<span class="hljs-subst">{time_str}</span>.png'</span>
2252+
filename = <span class="hljs-string">f'profile-<span class="hljs-subst">{datetime.now():%Y%m%d%H%M%S}</span>.png'</span>
22542253
drawer = output.GraphvizOutput(output_file=filename)
22552254
<span class="hljs-keyword">with</span> PyCallGraph(drawer):
22562255
&lt;code_to_be_profiled&gt;
@@ -2547,12 +2546,12 @@
25472546
&lt;Surf&gt;.set_at((x, y), color) <span class="hljs-comment"># Updates pixel.</span>
25482547
&lt;Surf&gt;.blit(&lt;Surf&gt;, (x, y)) <span class="hljs-comment"># Draws passed surface to the surface.</span>
25492548
</code></pre>
2550-
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.transform <span class="hljs-keyword">import</span> scale,
2549+
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.transform <span class="hljs-keyword">import</span> scale, ...
25512550
&lt;Surf&gt; = scale(&lt;Surf&gt;, (width, height)) <span class="hljs-comment"># Returns scaled surface.</span>
25522551
&lt;Surf&gt; = rotate(&lt;Surf&gt;, degrees) <span class="hljs-comment"># Returns rotated and scaled surface.</span>
25532552
&lt;Surf&gt; = flip(&lt;Surf&gt;, x_bool, y_bool) <span class="hljs-comment"># Returns flipped surface.</span>
25542553
</code></pre>
2555-
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.draw <span class="hljs-keyword">import</span> line,
2554+
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pygame.draw <span class="hljs-keyword">import</span> line, ...
25562555
line(&lt;Surf&gt;, color, (x1, y1), (x2, y2), width) <span class="hljs-comment"># Draws a line to the surface.</span>
25572556
arc(&lt;Surf&gt;, color, &lt;Rect&gt;, from_rad, to_rad) <span class="hljs-comment"># Also: ellipse(&lt;Surf&gt;, color, &lt;Rect&gt;)</span>
25582557
rect(&lt;Surf&gt;, color, &lt;Rect&gt;) <span class="hljs-comment"># Also: polygon(&lt;Surf&gt;, color, points)</span>

Diff for: pdf/index_for_pdf.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h3 id="f">F</h3>
5151
<p><strong>files, <a href="#print">22</a>-<a href="#memoryview">29</a>, <a href="#runsabasicfileexplorerintheterminal">34</a>, <a href="#encodedecode">46</a></strong><br>
5252
<strong>filter function, <a href="#mapfilterreduce">11</a></strong><br>
5353
<strong>floats, <a href="#abstractbaseclasses">4</a>, <a href="#floats">6</a>, <a href="#types">7</a></strong><br>
54-
<strong>format, <a href="#format">6</a>-<a href="#comparisonofpresentationtypes">7</a></strong><br>
54+
<strong>format, <a href="#format">6</a>-<a href="#comparisonofpresentationtypes">7</a>, <a href="#callgraph">37</a></strong><br>
5555
<strong>functools module, <a href="#mapfilterreduce">11</a>, <a href="#partial">12</a>, <a href="#debuggerexample">13</a>, <a href="#sortable">16</a></strong><br>
5656
<strong>futures, <a href="#threadpoolexecutor">30</a></strong> </p>
5757
<h3 id="g">G</h3>

Diff for: pdf/index_for_pdf_print.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h3 id="f">F</h3>
5151
<p><strong>files, 22-29, 34, 46</strong><br>
5252
<strong>filter function, 11</strong><br>
5353
<strong>floats, 4, 6, 7</strong><br>
54-
<strong>format, 6-7</strong><br>
54+
<strong>format, 6-7, 37</strong><br>
5555
<strong>functools module, 11, 12, 13, 16</strong><br>
5656
<strong>futures, 30</strong> </p>
5757
<h3 id="g">G</h3>

0 commit comments

Comments
 (0)