24式,加速你的Python
作者 | 梁云
来源 | Python与算法之美(id:Python_Ai_Road)
一、分析代码运行时间
第1式:测算代码运行时间
- 平凡方法
- 快捷方法(jupyter环境)
第2式:测算代码多次运行平均时间
- 平凡方法
- 快捷方法(jupyter环境)
第3式:按调用函数分析代码运行时间
- 平凡方法
- 快捷方法(jupyter环境)
第4式:按行分析代码运行时间
- 平凡方法
- 快捷方法(jupyter环境)
二、加速你的查找
第5式:用set而非list进行查找
- 低速方法
- 高速方法
第6式:用dict而非两个list进行匹配查找
- 低速方法
- 高速方法
三、加速你的循环
第7式:优先使用for循环而不是while循环
- 低速方法
- 高速方法
第8式:在循环体中避免重复计算
- 低速方法
- 高速方法
四、加速你的函数
第9式:用循环机制代替递归函数
- 低速方法
- 高速方法
第10式:用缓存机制加速递归函数
- 低速方法
- 高速方法
第11式:用numba加速Python函数
- 低速方法
- 高速方法
五、使用标准库函数进行加速
第12式:使用collections.Counter加速计数
- 低速方法
- 高速方法
第13式:使用collections.ChainMap加速字典合并
- 低速方法
- 高速方法
六,使用高阶函数进行加速
第14式:使用map代替推导式进行加速
- 低速方法
- 高速方法
第15式:使用filter代替推导式进行加速
- 低速方法
- 高速方法
七、使用numpy向量化进行加速
第16式:使用np.array代替list
- 低速方法
- 高速方法
第17式:使用np.ufunc代替math.func
- 低速方法
- 高速方法
第18式:使用np.where代替if
- 低速方法
- 高速方法
八、加速你的Pandas
第19式:使用csv文件读写代替excel文件读写
- 低速方法
- 高速方法
第20式:使用pandas多进程工具pandarallel
- 低速方法
- 高速方法
九、使用Dask进行加速
第21式:使用dask加速dataframe
- 低速方法
- 高速方法
第22式:使用dask.delayed进行加速
- 低速方法
- 高速方法
十、应用多线程多进程加速
第23式:应用多线程加速IO密集型任务
- 低速方法
- 高速方法
第24式:应用多进程加速CPU密集型任务
- 低速方法
- 高速方法
(*本文仅代表作者观点,转载请联系原作者)
◆
征稿
◆
参与投稿,加入作者群,成为全宇宙最优秀的技术人儿~
推荐阅读
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。