Skip to content

Commit 6c71c1d

Browse files
committed
Wording and wrapping for scenarios/speed.
1 parent 7a65571 commit 6c71c1d

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

docs/scenarios/speed.rst

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ C Extensions
6868
Cython
6969
------
7070

71-
`Cython <http://cython.org/>`_ implements a superset of the Python language
72-
with which you are able to write C and C++ modules for Python. Cython also
73-
allows you to call functions from compiled C libraries. Using Cython allows
74-
you to take advantage of Python's strong typing of variables and operations.
71+
`Cython <http://cython.org/>`_ implements a superset of the Python language
72+
with which you are able to write C and C++ modules for Python. Cython also
73+
allows you to call functions from compiled C libraries. Using Cython allows
74+
you to take advantage of Python's strong typing of variables and operations.
7575

7676
Here's an example of strong typing with Cython:
7777

@@ -100,11 +100,11 @@ Here's an example of strong typing with Cython:
100100
return result
101101
102102
103-
This implementation of an algorithm to find prime numbers has some additional keywords instead of the next one, which is implemented in pure Python:
103+
This implementation of an algorithm to find prime numbers has some additional
104+
keywords compared to the next one, which is implemented in pure Python:
104105

105106
.. code-block:: python
106107
107-
108108
def primes(kmax):
109109
"""Calculation of prime numbers in standard Python syntax"""
110110
@@ -125,7 +125,7 @@ This implementation of an algorithm to find prime numbers has some additional ke
125125
n = n + 1
126126
return result
127127
128-
Notice that in the Cython version you declare integers and integer arrays for
128+
Notice that in the Cython version you declare integers and integer arrays
129129
to be compiled into C types while also creating a Python list:
130130

131131

@@ -148,12 +148,14 @@ to be compiled into C types while also creating a Python list:
148148
p= range(1000)
149149
result = []
150150
151-
What is the difference? In the upper Cython version you can see the declaration of the variable types and the integer array
152-
in a similar way like in standard C. For example `cdef int n,k,i` in line 3. This additional type declaration (e.g. integer)
153-
allows the Cython compiler to generate more efficient C code from the second code. While standard Python code is saved in :file:`*.py` files,
154-
Cython code is saved in :file:`*.pyx` files.
151+
What is the difference? In the upper Cython version you can see the
152+
declaration of the variable types and the integer array in a similar way as
153+
in standard C. For example `cdef int n,k,i` in line 3. This additional type
154+
declaration (i.e. integer) allows the Cython compiler to generate more
155+
efficient C code from the second version. While standard Python code is saved
156+
in :file:`*.py` files, Cython code is saved in :file:`*.pyx` files.
155157

156-
And what is with the speed? So let's try it!
158+
What's the difference in speed? Let's try it!
157159

158160
.. code-block:: python
159161
@@ -179,19 +181,23 @@ And what is with the speed? So let's try it!
179181
print "Python time: %s" %(t2-t1)
180182
181183
182-
These both lines need a remark:
184+
These lines both need a remark:
183185

184186
.. code-block:: python
185187
186188
import pyximport
187189
pyximport.install()
188190
189191
190-
The `pyximport` module allows you to import :file:`*.pyx` files (e.g., :file:`primesCy.pyx`) with the Cython-compiled version of the `primes` function.
191-
The `pyximport.install()` command allows the Python interpreter to start the Cython compiler directly to generate C-code,
192-
which is automatically compiled to a :file:`*.so` C-library. Cython is able to import this library for you in your Python-code.
193-
Very easy and very efficient. With the `time.time()` function you are able to compare the time between this 2 different calls to find 500 prime numbers.
194-
On a standard notebook (dual core AMD E-450 1.6 GHz), the measured values are:
192+
The `pyximport` module allows you to import :file:`*.pyx` files (e.g.,
193+
:file:`primesCy.pyx`) with the Cython-compiled version of the `primes`
194+
function. The `pyximport.install()` command allows the Python interpreter to
195+
start the Cython compiler directly to generate C-code, which is automatically
196+
compiled to a :file:`*.so` C-library. Cython is then able to import this
197+
library for you in your Python code, easily and efficiently. With the
198+
`time.time()` function you are able to compare the time between these 2
199+
different calls to find 500 prime numbers. On a standard notebook (dual core
200+
AMD E-450 1.6 GHz), the measured values are:
195201

196202
.. code-block:: console
197203
@@ -200,14 +206,15 @@ On a standard notebook (dual core AMD E-450 1.6 GHz), the measured values are:
200206
Python time: 0.0566 seconds
201207
202208
209+
And here the output of an embedded `ARM beaglebone <http://beagleboard.org/Products/BeagleBone>`_ machine:
203210

204-
And here the output of an embedded `ARM beaglebone <http://beagleboard.org/Products/BeagleBone>`_ machine:
205211
.. code-block:: console
206212
207213
Cython time: 0.0196 seconds
208214
209215
Python time: 0.3302 seconds
210216
217+
211218
Pyrex
212219
-----
213220

0 commit comments

Comments
 (0)