avalon-fsn Python 编译构造工具开源项目

我要开发同款
匿名用户2019年09月02日
27阅读
开发技术Python
所属分类开发工具、Python开发工具
授权协议Mulan

作品详情

avalon-fsn

avalon-fsn是一个Python的编译构造工具,能够将你的代码Cython

使用avalon-fsn的好处代码Cython化:Windows下把代码编译为pyd,Linux下把代码编译为.so,有效的保护源代码获得性能提升:能够在不做任何代码级别优化的情况下,对Python代码进行性能提升安装pipinstallavalon-fsn编译项目avalon-fsn-buildbuild_ext

编译完毕后,对应的文件会在./build/lib*底下

使用编译后的文件avalon-fsn-release

执行此命令会把build目录下的编译文件替换到根目录下,仅在编译发布环境使用

##配置文件当有定制参数的时候,可以在项目根目录下新建配置文件avalon-fsn.json

{"remove_models":[],"remove_files":[]}配置名称配置描述remove_models不参与编译的模块remove_files不参与编译的文件性能对比importtimedefrun():time_start=time.time()importsysdefmake_tree(depth):ifnotdepth:returnNone,Nonedepth-=1returnmake_tree(depth),make_tree(depth)defcheck_tree(node):(left,right)=nodeifnotleft:return1return1+check_tree(left)+check_tree(right)min_depth=4max_depth=max(min_depth+2,17)stretch_depth=max_depth+1print("stretchtreeofdepth%d\tcheck:"%stretch_depth,check_tree(make_tree(stretch_depth)))long_lived_tree=make_tree(max_depth)iterations=2**max_depthfordepthinrange(min_depth,stretch_depth,2):check=0foriinrange(1,iterations+1):check+=check_tree(make_tree(depth))print("%d\ttreesofdepth%d\tcheck:"%(iterations,depth),check)iterations//=4print("longlivedtreeofdepth%d\tcheck:"%max_depth,check_tree(long_lived_tree))time_end=time.time()print('timecost',time_end-time_start,'s')纯Pythonstretchtreeofdepth18check:524287131072treesofdepth4check:406323232768treesofdepth6check:41615368192treesofdepth8check:41861122048treesofdepth10check:4192256512treesofdepth12check:4193792128treesofdepth14check:419417632treesofdepth16check:4194272longlivedtreeofdepth17check:262143timecost11.279994249343872sCython化stretchtreeofdepth18check:524287131072treesofdepth4check:406323232768treesofdepth6check:41615368192treesofdepth8check:41861122048treesofdepth10check:4192256512treesofdepth12check:4193792128treesofdepth14check:419417632treesofdepth16check:4194272longlivedtreeofdepth17check:262143timecost1.9600331783294678s

简单编译之后,性能直接就提升近6倍

查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论