一个模块,可以方便地对代码部分进行计时。
easytimer的Python项目详细描述
关于
一个模块,可以方便地对代码部分进行计时。在
安装
pip install easytimer
使用
- tick()启动一个新的分区计时器并结束上一个分区计时器
- tock()打印出目前为止每个部分的运行时
- 使用相同的名称多次调用tick()会增加该名称的运行总数
示例
^{pr2}$--- Timer Results ---
tick 1 - 0.10s
tick 2 - 0.20s
tick 3 - 0.10s
---------------------
# Example with named sectionstick('Setup')time.sleep(0.1)tick('Multi')time.sleep(0.2)tick('Intermediate')time.sleep(0.3)tick('Multi')time.sleep(0.4)tock()
--- Timer Results ---
Setup - 0.10s
Multi - 0.60s
Intermediate - 0.30s
---------------------
# Example with looptick("Part A")time.sleep(0.1)foriinrange(10):tick('Part B1')time.sleep(0.02)tick('Part B2')time.sleep(0.03)tick("Part C")time.sleep(0.4)tock()
--- Timer Results ---
Part A - 0.10s
Part B1 - 0.20s
Part B2 - 0.30s
Part C - 0.40s
---------------------
- 项目
标签: