1 Star 1 Fork 0

g1879 / TimePinner

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

简介

TimePinner 是一个简单的计时工具。

类似于代码中的秒表。

可标记多个点,以记录若干段时间长度。

每段时间可以命名,以方便记忆,也可跳过无须记录的时间段。

安装与导入

安装

pip install TimePinner

导入

from TimePinner import Pinner

使用方法

创建对象

from TimePinner import Pinner

pinner = Pinner()

记录时间点

使用pin()方法记录一个时间点,可以通过text参数给该时间点命名。

记录的时候会把当前时间段打印出来,可用show()参数设置不打印。

也可以在创建对象时用show_everytime参数设置是否打印。

pin()show参数比创建对象时show_everytime参数优先级高。

pinner = Pinner()
pinner.pin()  # 记录起始点
sleep(1)
pinner.pin('记录1')
sleep(2)
pinner.pin('记录2', show=False)  # 不打印该节点

输出:

0.0
记录1:1.0084643

跳过时间段

有些时间段无须记录,用skip()方法跳过。下一个记录会以当前点作为起始。

pinner.skip()

打印结果

通过show()方法,可以把记录到的时间段打印出来。

记录1:1.007383
记录2:2.0145351000000002

获取结果

通过records属性获取各个记录的时间段,每个时间段为一个两位元组。

print(pinner.records)

输出:

[('记录1', 1.0084643), ('记录2', 2.0126551999999998)]

获取最短的时间段

通过winner属性可以获取最短的时间段,用于对比几段代码运行时间。

print(pinner.winner)

输出:

('记录1', 1.0084643)
MIT License Copyright (c) 2022 g1879 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

这是一个用于代码中计时的小工具。 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/g1879/TimePinner.git
git@gitee.com:g1879/TimePinner.git
g1879
TimePinner
TimePinner
master

搜索帮助