If you want to be present you need send an email to quentin.rouvier@epitech.eu with the following object:
[WSCYTHON] Nom Prénom
/!\ Put your real firstname and lastname
In the mail share a .zip or .tar.gz file with the contents of your repository.
/!\ Please run python3 setup.py clean before compressing your project
Any work you do needs to be in the email, if you don't do this or didn't advance into the workshop at all you will be marked absent.
Cython is a language that makes writing C extensions for the Python language as easy as Python itself. In this workshop we will be using Cython to benchmark two different algorithms coded in Python and C(ython).
You will find two simple alogrithms made with python. Our job today is to make them work in C(ython).
In the demo/ folder you will find a file named demo.py with the following content:
def pyloop():
# ...
def pycount():
# ...In the demo/cython/ folder you will find a file named demo.pyx with the following content:
def cloop():
# TODO: Fill this function
def ccount():
# TODO: Fill this functionTo compile cython code to C/C++ you will use cythonise. It will create a library (.so, for those unfamiliar with that extension it's similar to a .a library like the libmy.a that you should all be familiar with).
To compile the code you will use the following command:
pip3 install -e ./!\ Make sure to keep any __init__.py files you see, they are empty but required for the setup.
In the current directory you will find the bench.py file:
import timeit
def main():
# TODO: Fill this function
if __name__ == "__main__":
main()Using the timeit module call all 4 functions and print the results.
In this exercise we will rewrite the ccount() function with a more C-like syntax, create a new function underneath named betterccount():
def betterccount():
# TODO: Fill this functionTake a look at the documentation here.
/!\ Make sure that you select Cython syntax and not Pure Python in the documentation. Those are two different approaches. Pure python is not necessary for our example.
Let's go back to our bench.py file. Add the new betterccount() function and compare the results.
As a bonus if this subject interests you, you can look at the assembly code behind all this code.
Here is a website that will allow you to do that: godbolt.org,
You can paste your code in the left editor and look at the assembly operation in the right editor, here is an example with the pyloop() function


