计时代码块
项目描述
harrison
计时代码块。
用作with
语句的上下文表达式
>>> from harrison import Timer
>>> with Timer() as t:
>>> ...
>>> print t.elapsed_time_ms
12345
当初始化时传递一个描述字符串,完成时会打印经过的时间,以该描述为键。
>>> with Timer('My expensive block of code'):
>>> ...
My expensive block of code: 12345 ms
您还可以显式开始和停止计时器
timer = Timer()
timer.start()
some_expensive_function(...)
print timer.elapsed_time_s
another_expensive_function(...)
timer.stop()
print timer.elapsed_time_s
您还可以使用装饰器来计时函数的每次执行
from harrison import profile
@profile('Describes the function')
def some_function():
pass
# Without args, the function name (e.g. 'some_function') will be used
# as the description.
@profile()
def another_function():
pass
您还可以使用RegisteredTimer
,它将多个命名计时器组合在一起,提供序列化它们的时间的实用程序,以及一个可选的全局计时器注册表。
以英国木匠和钟表匠约翰·哈里森的名字命名,他发明了海上计时器。
类似库
这与contexttimer库类似,但该库的许可证是GPLv3,比这里使用的双条款BSD许可证更为限制性。
开发
pip install -r requirements_dev.txt
rake lint
贡献
欢迎提交拉取请求!
支持
如果您遇到问题,请告诉我们。
许可证
该项目采用双条款BSD许可证。
项目详情
关闭
metaboharrison-1.2.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 04aba6c0ca2c0c94c66d2a34c5376aefd60b703769b94335ba0f89e5bcd4a952 |
|
MD5 | dbe21c25efa88b3cc62d243d14f5616b |
|
BLAKE2b-256 | 79876e651781d1ba2be3a3821a146968bc0faa4967d8c2686c08e4cc3bb57ffa |