简介
TimePinner 是一个简单的计时工具。
类似于代码中的秒表。
可标记多个点,以记录若干段时间长度。
每段时间可以命名,以方便记忆,也可跳过无须记录的时间段。
安装与导入
安装
pip install TimePinner
导入
from TimePinner import Pinner
使用方法
创建对象
from TimePinner import Pinner
pinner = Pinner()
记录时间点
使用pin()方法记录一个时间点,并返回时间差,可以通过text参数给该时间点命名。
可用show参数设置是否打印。
也可以在创建对象时用show_everytime参数设置是否打印。
pin()的show参数比创建对象时show_everytime参数优先级高。
如果all_time参数为True,打印和返回的是与第一个时间点的时间差。
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()方法,可以把记录到的时间段打印出来。
如果all_time参数为True,打印出来的是每个时间点与第一个时间点的时间差。
记录1:1.007383
记录2:2.0145351000000002
获取结果
通过records()方法获取各个记录的时间段,每个时间段为一个两位元组。
如果all_time参数为True,打印出来的是每个时间点与第一个时间点的时间差。
print(pinner.records())
输出:
[('记录1', 1.0084643), ('记录2', 2.0126551999999998)]
获取最短的时间段
通过winner()方法可以获取最短的时间段,用于对比几段代码运行时间。
如果all_time参数为True,打印出来的是每个时间点与第一个时间点的时间差。
print(pinner.winner())
输出:
('记录1', 1.0084643)
重置
使用reset()方法清空已有记录并重新开始计时。
Metadata
Release files for TimePinner 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| timepinner-1.0.0.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| timepinner-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / timepinner-1.0.0.tar.gz
| Download URL | timepinner-1.0.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
178f94e257cce6293ab729bfc6da7c8950c1804118492c18516673dca5eb17a9
|
|
BLAKE2b-256 checksum How to use checksums |
07a5a3617a6082afac59d0717699d5d26c8a3907d77a2f81fe6a768e690a062e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / timepinner-1.0.0-py3-none-any.whl
| Download URL | timepinner-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71e9e3fa1f1ccadfb5ab4c41c0fc48b700d656bd86ed6e28d568b9b0b5625d50
|
|
BLAKE2b-256 checksum How to use checksums |
a2ae88bd3cb20e737c171563f1bacd6a626f2e7384fdba1e392c24c478e2307f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|