Daimon Blog

山在那里

Cython

简单的加密python代码(防君子不防小人),或者是要热点提速,可以考虑cython。常用的命令如下。

python代码编译成so

cat setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
  name = 'xxx decrypt lib',
  ext_modules = cythonize("xxx.pyx"),
)

python setup.py build_ext --inplace

参考:http://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html

python优化热点代码

优化热点之前,一定先用profile看看,热点代码是哪段。别瞎优化。

.c文件, 重写算法


文章分类目录