pypy 高性能python 解释器

发布时间 2023-12-14 09:38:28作者: 荣锋亮

pypy 是基于RPython 语言开发的cpython 替换工具

包含的特性

  • 高速
    使用了JIT 技术,运行比较快
  • 可以支持基于无栈模式
  • 沙箱支持
  • 对于现有python 周边的支持比较好
    当然可能也会有问题,但是大部分运行是可以的

参考使用

一个基于ffi 的集成,实际上目前pypy 已经集成了cffi,运行基于了venv

  • 参考代码
 
from cffi import FFI
 
ffi = FFI()
 
with open("bindings.h") as f:
    ffi.cdef(f.read())
 
# mac的动态链接库
lib = ffi.dlopen("libmylib.dylib")
 
print(lib.addv2(1, 2))
 
  • 运行效果

说明

以上是一个简单的学习试用,对于一些希望高性能运行的应用pypy 是值得试用的

参考资料

https://www.pypy.org/index.html
https://cffi.readthedocs.io/en/stable/
https://cppyy.readthedocs.io/en/latest/
https://rpython.readthedocs.io/en/latest/
https://doc.pypy.org/en/latest/cpython_differences.html
https://www.pypy.org/compat.html
https://hpyproject.org/