Skip to content

Commit 341af60

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#73 from rday/master
Speed file updates
2 parents 3bf7c90 + 2111060 commit 341af60

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

docs/scenarios/speed.rst

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,32 @@ Speed
33

44
CPython, the most commonly used implementation of Python, is slow for CPU bound tasks. `PyPy`_ is fast.
55

6-
.. todo:: Fill in stub for Speed comparisons
6+
Using a slightly modified version of `David Beazleys`_ CPU bound test code(added loop for multiple tests), you can see the difference between CPython and PyPy's processing.
7+
8+
::
9+
10+
PyPy
11+
$ ./pypy -V
12+
Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10)
13+
[PyPy 1.7.0 with GCC 4.4.3]
14+
$ ./pypy measure2.py
15+
0.0683999061584
16+
0.0483210086823
17+
0.0388588905334
18+
0.0440690517426
19+
0.0695300102234
20+
21+
::
22+
23+
CPython
24+
$ ./python -V
25+
Python 2.7.1
26+
$ ./python measure2.py
27+
1.06774401665
28+
1.45412397385
29+
1.51485204697
30+
1.54693889618
31+
1.60109114647
732

833
Context
934
:::::::
@@ -12,7 +37,13 @@ Context
1237
The GIL
1338
-------
1439

40+
`The GIL`_ (Global Interpreter Lock) is how Python allows multiple threads to operate at the same time. Python's
41+
memory management isn't entirely thread-safe, so the GIL is requried to prevents multiple threads from running
42+
the same Python code at once.
1543

44+
David Beazley has a great `guide`_ on how the GIL operates. He also covers the `new GIL`_ in Python 3.2. His
45+
results show that maximizing performance in a Python application requires a strong understanding of the GIL,
46+
how it affects your specific application, how many cores you have, and where your application bottlenecks are.
1647

1748
C Extentions
1849
------------
@@ -21,8 +52,8 @@ C Extentions
2152
The GIL
2253
-------
2354

24-
25-
55+
`Special care`_ must be taken when writing C extensions to make sure you register your threads
56+
with the interpreter.
2657

2758
C Extentions
2859
::::::::::::
@@ -57,4 +88,9 @@ Multiprocessing
5788
---------------
5889

5990

60-
.. _`PyPy`: http://pypy.org
91+
.. _`PyPy`: http://pypy.org
92+
.. _`The GIL`: http://wiki.python.org/moin/GlobalInterpreterLock
93+
.. _`guide`: http://www.dabeaz.com/python/UnderstandingGIL.pdf
94+
.. _`New GIL`: http://www.dabeaz.com/python/NewGIL.pdf
95+
.. _`Special care`: http://docs.python.org/c-api/init.html#threads
96+
.. _`David Beazleys`: http://www.dabeaz.com/GIL/gilvis/measure2.py

0 commit comments

Comments
 (0)