Skip to content

zhanglongqi/speedup_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

speedup_python

Using C and Cython to speedup your python

Thanks this blog:

  1. Compile C file to dynamic shared library

    In Mac: gcc -dynamiclib -o libfunctions.dylib functions.c

    In Linux: gcc -Wall -fPIC -shared -o libfunctions.so functions.c

  2. Compile Cython file There are two ways to do this:

    1. python3 setup.py build_ext --inplace This will generate .o and .so file. Then import fibRec_Cython in the caller

    2. using pyximport In the caller:

      import pyximport
      pyximport.install()
      import fibRec_Cython
  3. python3 main.py

Result on my machine:

Python	: 0.8736008979976759
Cython	: 0.25456177699379623
C  lib	: 0.013578268997662235

About

Using C and Cython to speedup your python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published