话不多说,Hello World:
#hello.pyx
def say_hello_to(name):
print("Hello %s!" % name)
#setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("hello", ["hello.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
执行:
python setup.py build_ext --inplace
欧了~第一个cython算是完成,就是那个 hello.so的东东,如同普通的py文件一样使用即可。
可是,为毛要cython这么麻烦捏?速度啊速度!
def f(x):
return x**2-x
def integrate_f(a, b, N):
s = 0
dx = (b-a)/N
for i in range(N):
s += f(a+i*dx)
return s * dx
cython一下,提高35%!还不满意?那么稍微再改改:
def f(double x):
return x**2-x
def integrate_f(double a, double b, int N):
cdef int i
cdef double s, dx
s = 0
dx = (b-a)/N
for i in range(N):
s += f(a+i*dx)
return s * dx
4倍啊4倍!和原生的c一个级别了!!什么?还不满意?好吧,等我深入学习下先~
分享到:
相关推荐
[Packt Publishing] Cython 编程学习教程 (英文版) [Packt Publishing] Learning Cython Programming (E-Book) ☆ 图书概要:☆ Expand your existing legacy applications in C using Python Overview Extend ...
It’s possible with Cython, the compiler and hybrid programming language used by foundational packages such as NumPy, and prominent in projects including Pandas, h5py, and scikits-learn. In this ...
Cython封装Callback函数文章 示例 http://blog.csdn.net/i2cbus/article/details/18415333
Cython: A Guide for Python Programmers covers all you need to know about the eponymous creole programming language and Python-to-C compiler. If you have heard of Cython and want to find out more, or ...
参考Cython官方文档编写而来的一个Cython封装C++的示例demo,可入门学习。
此为适用于linux系统python3.6的cython安装包,版本为0.29
cython_bbox-0.1.3 未修改pip源码
Learning Cython Programming
python库。 资源全名:Cython-0.29.3.tar.gz
Python第三方包 Cython
引言 通常,在 Python 中写循环(特别是多重循环)非常的慢,在文章 //www.jb51.net/article/133807.htm中,我们的...cimport cython DTYPE = np.float ctypedef np.float_t DTYPE_t def update_state(np.ndarray[DTYP
Cython-0.29.30-py3-none-any.whl
OrderedDict的Cython实现
详细介绍了Cython文件在window与linux下的编译,以实际例子说明。
Cython是一个编程语言,它通过类似Python的语法来编写C扩展并可以被Python调用.既具备了Python快速开发的特点,又可以让代码运行起来像C一样快,同时还可以方便地调用C library。译出最终的Python可调用的模块。
由python、C、Cython实现的二叉树树源码。树是一种重要的非线性数据结构,直观地看,它是数据元素(在树中称为结点)按分支关系组织起来的结构,很象自然界中的树那样。树结构在客观世界中广泛存在,如人类社会的...
《Cython入门》 示例 http://blog.csdn.net/i2cbus/article/details/18181637
Cython-0.23.3.tar.gz : Cython-0.23.3安装包
Cython-0.29.23-cp27-cp27m-win32