计时一段代码
harrison的Python项目详细描述
哈里森
计时一段代码。
用作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(...)printtimer.elapsed_time_sanother_expensive_function(...)timer.stop()printtimer.elapsed_time_s
您还可以使用decorator计时函数的每次执行:
fromharrisonimportprofile@profile('Describes the function')defsome_function():pass# Without args, the function name (e.g. 'some_function') will be used# as the description.@profile()defanother_function():pass
您还可以使用RegisteredTimer
,它将一组
计时器,提供用于序列化其时间的实用程序,以及可选的全局
计时器注册表。
以英国木匠兼钟表匠约翰·哈里森的名字命名 发明了marine chronometer。
类似库
这与库contexttimer类似,但该库已获得许可 在gplv3下,它比使用的两条bsd许可证更具限制性 在这里。
开发
pip install -r requirements_dev.txt rake lint
贡献
拉请求欢迎!
支架
如果你有问题,请告诉我们。
致谢
这个项目是由Paul Melnikow在Body Labs打包的。谢谢 到身体实验室进行储存库转移。
许可证
该项目根据两条BSD许可证获得许可。