Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created May 29, 2023 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hermann-SW/a7431aff0022f9ee81f3cf3fa6c7a480 to your computer and use it in GitHub Desktop.
Save Hermann-SW/a7431aff0022f9ee81f3cf3fa6c7a480 to your computer and use it in GitHub Desktop.
Short demo of using Cython, setting language_level, compare runtimes, ...
#!/bin/bash
pip install setuptools Cython gmpy2
rm -rf /tmp/tst && mkdir /tmp/tst && cd /tmp/tst
wget -q https://gist.githubusercontent.com/Hermann-SW/061d33b47325bd15a4033b33d3f7c4c9/raw/9900616d98b6acdd50c436d9ae914a1c5d81f2b2/sq2_cg.py
mv sq2_cg.py sq2_cg.pyx
cat << EOF > setup.py
from setuptools import setup
from Cython.Build import cythonize
setup( ext_modules = cythonize("sq2_cg.pyx", language_level=3) )
EOF
python setup.py build_ext --inplace > log
echo "import sq2_cg" > import.py
echo -n "sq2_cg.pyx: " && python sq2_cg.pyx > out
echo -n "import.py: " && python import.py > out2
echo "diff:" && diff out out2
@Hermann-SW
Copy link
Author

Hermann-SW commented May 30, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment