2019-09-03
JiangRen Mr
avalon-fsn 是一个Python的编译构造工具,能够将你的代码Cython化
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')
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
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倍。
本文章转载自开源中国。
AI一日Workshop:学会GPT-4o Canvas、Perplexity AI、NotebookLM三大工具
2025/03/15 05:00 (Sydney)
商业数据分析实战班第17期(Self-Paced + Tutor)
2025/03/15 06:13 (Sydney)
数据工程全栈班第16期
2025/03/23 07:02 (Sydney)
地址
Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)Level 2, 171 La Trobe St, Melbourne VIC 3000四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号Business Hub, 155 Waymouth St, Adelaide SA 5000Disclaimer
JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.
匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议
© 2017-2024 JR Academy Pty Ltd. All rights reserved.
ABN 26621887572