You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/scenarios/speed.rst
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,8 +124,8 @@ Strong typing with Cython:
124
124
125
125
.. code-block:: python
126
126
127
-
#primes function with additional Cython code:
128
-
defprimes(int kmax):
127
+
#primes function with additional Cython code:
128
+
defprimes(int kmax):
129
129
cdef int n, k, i
130
130
cdef int p[1000]
131
131
result = []
@@ -135,7 +135,7 @@ Normal variable definition in Python:
135
135
.. code-block:: python
136
136
137
137
#primes in standard Python syntax:
138
-
defprimes( kmax):
138
+
defprimes( kmax):
139
139
p=range(1000)
140
140
result = []
141
141
@@ -149,7 +149,8 @@ And what is with the speed? So lets try it!
149
149
150
150
import time
151
151
#activate pyx compiler
152
-
import pyximport; pyximport.install()
152
+
import pyximport
153
+
pyximport.install()
153
154
#primes implemented with Cython
154
155
import primesCy
155
156
#primes implemented with Python
@@ -172,14 +173,15 @@ Where is the magic? Here it is:
172
173
173
174
.. code-block:: python
174
175
175
-
import pyximport; pyximport.install()
176
+
import pyximport
177
+
pyximport.install()
176
178
177
179
178
180
With the module `pyximport` you are able to import Cython `*.pyx` files, in this case `primesCy.pyx`, with the Cython
179
181
version of the primes function.
180
182
The `pyximport.install()` command allows the Python interpreter to start the Cython compiler directly to generate C-code,
181
183
which is automatically compiled to a `*.so` C-library. ... and Cython is able to import this library for you in your Python-code.
182
-
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.
184
+
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.
183
185
184
186
Here is the output of an embedded `ARM beaglebone <http://beagleboard.org/Products/BeagleBone>`_ machine:
0 commit comments