各种python代码的简单计时。

timeship的Python项目详细描述


时隙

时间片使您可以轻松、透明地在python代码中计时执行时间。

其概念是在代码中设置锚定,指定计时路线。Timeship模块将为指定的路由计时,并透明地通知您它们的执行时间。

安装

可以使用pip通过:

安装Timeship
pip install timeship

演示

只需执行下面的python片段就可以看到sea上的时间轴!

importtimefromtimeshipimporttimeshipwithtimeship.Anchor("BuildShip"):withtimeship.Anchor("CollectMaterial"):time.sleep(0.2)withtimeship.Anchor("CarftHull"):time.sleep(0.3)withtimeship.Anchor("CraftMast"):time.sleep(0.4)withtimeship.Anchor("HoistSail"):time.sleep(0.1)withtimeship.Anchor("Sail"):time.sleep(0.6)timeship.plot("timeship_demo")

用法

您有两个基本的不同选项来设置锚定

锚定函数

第一个选项是使用Timeships锚定函数,如下所示:

# set anchor Arrrtimeship.anchor("Arrr")# execute codetime.sleep(0.1)# release anchor Arrrtimeship.anchor("Arrr",release=True)# set anchor Orrrtimeship.anchor("Orrr")# execute some codetime.sleep(0.4)# additionally set anchor Errrtimeship.anchor("Errr")# execute some other codetime.sleep(0.4)# release all active anchors by not specifying a nametimeship.anchor()

上下文

第二种选择是使用上下文

withtimeship.Anchor("setup"):time.sleep(0.1)

嵌套

时间片还支持嵌套上下文。 可以使用斜线(context/subcontext)表示法指定嵌套计时上下文:

timeship.anchor("xdata/load")time.sleep(0.1)timeship.anchor()timeship.anchor("xdata/augment")

或者通过嵌套上下文:

withtimeship.Anchor("ydata"):withtimeship.Anchor("load"):# execute ydata loading codetime.sleep(0.2)withtimeship.Anchor("augment"):# execute ydata augmentation codetime.sleep(0.3)

或等效:

withtimeship.Anchor("zdata/load"):# execute zdata loading codetime.sleep(0.2)withtimeship.Anchor("zdata/augment"):# execute zdata augmentation codetime.sleep(0.3)

绘制计时数据

在代码末尾,使用plot函数绘制结果。timeships plotting函数(timeship.plot())使用index.html创建一个目录(由dir参数指定),该目录包含一个d3绘图,其中包含可以通过webbrowser查看的计时数据。

timeship.plot(dir="timeship")

这将创建一个新目录(在本例中称为“timeship”)并存储一个html页面,其中包含计时数据的清晰可视化。

穿越时空,阿瑞!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用Java学习Eclipse可视化编辑器Swing   eclipse如何找到运行Java程序所需的时间?   JAVA用于在Tomcat 8上运行Jena API的lang.UnsupportedClassVersionError   java在Main中调用字符串方法   javascript“子进程”。exec无法运行Java函数   java如何使用Gmail API获取电子邮件正文内容   java为什么客户端看不到服务器发送的第一条消息?   java无法在安卓 WebView中滚动到顶部   从服务器运行web服务时,java代码中的日期为空   从子任务返回后执行后台任务时发生java错误   java无法一致地处理弹出窗口   java(Android)通过蓝牙向µ控制器发送字节   java无法在emulator中启动AVD?安卓工作室   Android Java应用程序正在冻结,没有返回错误消息   java如何使用TestNg记录测试历史?