mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Mark up files & directories
This commit is contained in:
@@ -150,8 +150,8 @@ to be compiled into C types while also creating a Python list:
|
||||
|
||||
What is the difference? In the upper Cython version you can see the declaration of the variable types and the integer array
|
||||
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)
|
||||
allows the Cython compiler to generate more efficient C code from the second code. While standard Python code is saved in `*.py` files,
|
||||
Cython code is saved in `*.pyx` files.
|
||||
allows the Cython compiler to generate more efficient C code from the second code. While standard Python code is saved in :file:`*.py` files,
|
||||
Cython code is saved in :file:`*.pyx` files.
|
||||
|
||||
And what is with the speed? So lets try it!
|
||||
|
||||
@@ -187,9 +187,9 @@ These both lines need a remark:
|
||||
pyximport.install()
|
||||
|
||||
|
||||
The `pyximport` module allows you to import `pyx` files (e.g., `primesCy.pyx`) with the Cython-compiled version of the `primes` function.
|
||||
The `pyximport` module allows you to import :file:`*.pyx` files (e.g., :file:`primesCy.pyx`) with the Cython-compiled version of the `primes` function.
|
||||
The `pyximport.install()` command allows the Python interpreter to start the Cython compiler directly to generate C-code,
|
||||
which is automatically compiled to a `*.so` C-library. Cython is able to import this library for you in your Python-code.
|
||||
which is automatically compiled to a :file:`*.so` C-library. Cython is able to import this library for you in your Python-code.
|
||||
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.
|
||||
On a standard notebook (dual core AMD E-450 1.6 GHz), the measured values are:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user