Skip to main content

简介

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()方法清空已有记录并重新开始计时。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timepinner-1.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timepinner-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file timepinner-1.0.0.tar.gz.

File metadata

  • Download URL: timepinner-1.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for timepinner-1.0.0.tar.gz
Algorithm Hash digest
SHA256 178f94e257cce6293ab729bfc6da7c8950c1804118492c18516673dca5eb17a9
MD5 413c566579242ea04faf91201ed92c15
BLAKE2b-256 07a5a3617a6082afac59d0717699d5d26c8a3907d77a2f81fe6a768e690a062e

See more details on using hashes here.

File details

Details for the file timepinner-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: timepinner-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for timepinner-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71e9e3fa1f1ccadfb5ab4c41c0fc48b700d656bd86ed6e28d568b9b0b5625d50
MD5 1c04db30b8b6bfcafaac0c2886d5e3ca
BLAKE2b-256 a2ae88bd3cb20e737c171563f1bacd6a626f2e7384fdba1e392c24c478e2307f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page