Python基础——timeit模块
2015-12-08 09:22
651 查看
一般我们需要一段代码(主要是workhorse,程序的核心负重代码,如bp神经网络的整个SGD随机梯度下降的过程)的运行时间:
通过任一python IDE(PyCharm or Eclipse),我们可轻易地查看
显然这一层封装的最终目的是为了系统兼容性。
import timeit start_time = timeit.default_timer() for j in range(epochs): for i in range(n_train_batches): end_time = timeit.default_timer() print('ran for %.2fm'%(end_time-start_time)/60.) # timeit.default_timer()单位是秒
通过任一python IDE(PyCharm or Eclipse),我们可轻易地查看
timeit.default_timer()的源码:
if sys.platform == "win32": # On Windows, the best timer is time.clock() default_timer = time.clock else: # On most other platforms the best timer is time.time() defalut_time = time.time
显然这一层封装的最终目的是为了系统兼容性。
# On Windows >>> sys.platform 'Win32' # On CentOS 6.5 >>> sys.platform 'linux2'
相关文章推荐
- leetcode Binary Tree Right Side View python
- python培训Day7 随笔
- python 批量下载图片
- Python使用pygame模块编写俄罗斯方块游戏的代码实例
- 一波神奇的Python语句、函数与方法的使用技巧总结
- 使用Python编写简单的画图板程序的示例教程
- 笔记:Python进行数据库文件导出备份
- python-48:直接使用POST方法登录网站
- python-49: 爬虫模拟登陆源码
- 12.7 coding-python-mongo相关代码笔记
- 《Python核心编程》第10章 习题
- python语法笔记(三)
- Python字典里面创建字典
- leetcode Linked List Cycle II python
- leetcode Linked List Cycle python
- python对象内存分析
- Xcode搭建Python编译环境
- 【Python】Java转Python的一些水土不服
- leetcode LRU Cache python
- python核心编程-生成器