Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created January 12, 2020 08:19
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 e96031413/2d5a45357449af2d6330b9a0e2b4a4bf to your computer and use it in GitHub Desktop.
Save e96031413/2d5a45357449af2d6330b9a0e2b4a4bf to your computer and use it in GitHub Desktop.
Save your time with Cython!!!
'''
Simple Cython Usage
'''
''' Step0:Install Cython '''
sudo pip3 install cython
''' Step0:Install Cython '''
''' Step1:Create "a.py" '''
import sys
def fibo(n):
if n == 0: return 0
elif n == 1: return 1
return fibo(n-1) + fibo(n-2)
print(fibo(int(sys.argv[1])))
''' Step1:Create "a.py" '''
''' Step2:execute "a.py" '''
time python3 a.py 40
''' Step2:execute "a.py" '''
''' Step3:cp a.py a.pyx '''
''' Step4:Create setup.py '''
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize('a.pyx'))
''' Step5:Build it '''
python3 setup.py build_ext --inplace
''' Step5:Build it '''
''' Step6:Create "cython_A_.py" '''
import sys
import a
print(a)
''' Step6:Create "cython_A_.py" '''
''' Step7:Execute the program '''
time python3 a.py
''' Step7:Execute the program '''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment