~busykoala/cython_hints

This package demonstrates some useful cases how to use cython.
23ad0e0f — Matthias Osswald 1 year, 1 month ago
Update examples and add benchmark.
93338e85 — Matthias Osswald 1 year, 1 month ago
Gitignore autocompiled c/cpp files.
d4d89ba8 — Matthias Osswald 1 year, 1 month ago
Move test folder.

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~busykoala/cython_hints
read/write
git@git.sr.ht:~busykoala/cython_hints

You can also use your local clone with git send-email.

#Cython Hints

This package demonstrates some usefull cases how to use cython.

#Where to find what

In demo_cython.pyx there are examples for:

  • common function (cython "precompiled")
  • type safe function (cython "precompiled")
  • use c function from std lib
  • use cpp function from std lib
  • both python and c function (great for a recursion)
  • a "c compiled" function given a python wrapper.

In demo_c.pyx there is an example for external c code used within python.

In demo_cpp.pyx there is an example for external cpp code used within python.

#Example Benchmark

This benchmark is not done in an isolated environment but shows a little how big the velocity improvement can be using cython. The output was generated running show_magic which will run each fibonacci implementation to get the 40th number.

Time Python: 51.1399
Time Cython: 12.3765
Time Cython Typed: 12.1667
Time Cython hyprid Cpp: 0.3255
Time Cython hybrid C: 0.3413
Time Cython lib Cpp: 0.3378
Time Cython lib C: 0.3464

#Installation

git clone git@git.sr.ht:~busykoala/cython_hints
cd cython_hints
python3 -m venv .
source ./bin/activate
pip install -e .

#Run

show_magic

#Testing

source ./bin/activate
pip install -e ".[test]"
python -m pytest