avalon-fsn 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
avalon-fsn 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
avalon-fsn 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 Mulan
开发语言 Python
操作系统 跨平台
软件类型 开源软件
开源组织
地区 国产
投 递 者 小埋酱
适用人群 未知
收录时间 2019-09-02

软件简介

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倍

展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击加入讨论🔥(2)
2019/09/04 14:39

avalon-fsn 1.0.4 发布:提供 PyInstaller 打包命令,隐式导入不用愁

引入了PyInstaller打包,在你的项目根目录加入引导文件main.py, 一行命令,打包Python应用,同时解决了Sklearn,StaticsModels的隐式导入问题 avalon-fsn-package 记得要把代码Cython化一下哟,虽然不做也是可以的 打包后的应用

0
4
2019/09/01 19:20

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-relea...

1
8
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
2 评论
23 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部