avalon-fsn 1.0.0 发布:轻松加速你的 Python 代码
avalon-fsn
avalon-fsn 是一个Python的编译构造工具,能够将你的代码Cython化
使用avalon-fsn的好处
- 代码Cython化:Windows下把代码编译为pyd,Linux下把代码编译为.so,有效的保护源代码
- 获得性能提升:能够在不做任何代码级别优化的情况下,对Python代码进行性能提升
安装
pip install avalon-fsn
编译项目
avalon-fsn-build build_ext
编译完毕后,对应的文件会在./build/lib*
底下
使用编译后的文件
avalon-fsn-release
执行此命令会把build
目录下的编译文件替换到根目录下,仅在编译发布环境使用
##配置文件 当有定制参数的时候,可以在项目根目录下新建配置文件avalon-fsn.json
{ "remove_models": [], "remove_files": [] }
配置名称 | 配置描述 |
---|---|
remove_models | 不参与编译的模块 |
remove_files | 不参与编译的文件 |
性能对比
import time def run(): time_start = time.time() import sys def make_tree(depth): if not depth: return None, None depth -= 1 return make_tree(depth), make_tree(depth) def check_tree(node): (left, right) = node if not left: return 1 return 1 + check_tree(left) + check_tree(right) min_depth = 4 max_depth = max(min_depth + 2, 17) stretch_depth = max_depth + 1 print("stretch tree of depth %d\t check:" % stretch_depth, check_tree(make_tree(stretch_depth))) long_lived_tree = make_tree(max_depth) iterations = 2 ** max_depth for depth in range(min_depth, stretch_depth, 2): check = 0 for i in range(1, iterations + 1): check += check_tree(make_tree(depth)) print("%d\t trees of depth %d\t check:" % (iterations, depth), check) iterations //= 4 print("long lived tree of depth %d\t check:" % max_depth, check_tree(long_lived_tree)) time_end = time.time() print('time cost', time_end - time_start, 's')
纯Python
stretch tree of depth 18 check: 524287 131072 trees of depth 4 check: 4063232 32768 trees of depth 6 check: 4161536 8192 trees of depth 8 check: 4186112 2048 trees of depth 10 check: 4192256 512 trees of depth 12 check: 4193792 128 trees of depth 14 check: 4194176 32 trees of depth 16 check: 4194272 long lived tree of depth 17 check: 262143 time cost 11.279994249343872 s
Cython化
stretch tree of depth 18 check: 524287 131072 trees of depth 4 check: 4063232 32768 trees of depth 6 check: 4161536 8192 trees of depth 8 check: 4186112 2048 trees of depth 10 check: 4192256 512 trees of depth 12 check: 4193792 128 trees of depth 14 check: 4194176 32 trees of depth 16 check: 4194272 long lived tree of depth 17 check: 262143 time cost 1.9600331783294678 s
简单编译之后,性能直接就提升近6倍

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
PhalApi 2.8.1 发布,PHP 开源接口框架
PhalApi 2.8.1 [主要更新] 1、文件日志PhalApi\Logger\FileLogger区分隐式静默和显式异常两种模式,可通过\PhalApi\DI()->debug全局模式或初始化时指定调试模式。为调试模式时,若写入失败将500异常提示 1、文件配置PhalApi\Config\FileConfig区分隐式静默和显式异常两种模式,可通过\PhalApi\DI()->debug全局模式或初始化时指定调试模式。为调试模式时,若配置不存在将500异常提示 [辅助更新] [BUG修复] 1、URI路由匹配模式下默认接口读取不到 2、配置多个数据库时候, 调用get、update时会提示 dbs.tables should not be empty (issue 97)
- 下一篇
QuickJS 发布 2019-09-01 更新
QuickJS 发布了 2019-09-01 更新 增加globalThis 记录了JS_EVAL_FLAG_COMPILE_ONLY 增加import.meta.url 和 import.meta.main 增加 'debugger' 声明 bug修复 QuickJS 是一个小型并且可嵌入的 Javascript 引擎,它支持 ES2019 规范,包括模块,异步生成器和代理器。 它可选支持数学扩展,例如大整数 (BigInt),大浮点数 (BigFloat) 以及运算符重载。 主要功能 轻量而且易于嵌入:只需几个C文件,没有外部依赖,一个 x86 下的简单的“hello world”程序只要 180 KiB。 具有极低启动时间的快速解释器: 在一台单核的台式 PC 上,大约在 100 秒内运行 ECMAScript 测试套件 56000 次。运行时实例的完整生命周期在不到 300 微秒的时间内完成。 几乎完整实现 ES2019 支持,包括: 模块,异步生成器和和完整 Annex B 支持 (传统的 Web 兼容性)。 通过 100% 的 ECMAScript Test Suite 测...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS6,CentOS7官方镜像安装Oracle11G
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- MySQL8.0.19开启GTID主从同步CentOS8
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS7设置SWAP分区,小内存服务器的救世主
- CentOS6,7,8上安装Nginx,支持https2.0的开启