Skip to main content

一个用于代码中计时的小工具。

Project description

简介

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)

Project details


Download files

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

Source Distribution

TimePinner-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

TimePinner-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file TimePinner-0.1.1.tar.gz.

File metadata

  • Download URL: TimePinner-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for TimePinner-0.1.1.tar.gz
Algorithm Hash digest
SHA256 80a126b431a8007748432548f7a8107af777545e55578b60b51cc59804a76d4b
MD5 682e0b635eee005e8be036cb639cb4bd
BLAKE2b-256 6bceb8de139ada94308ea0e1e98cc55f899e2fdd91e11cfef09776b7560bb008

See more details on using hashes here.

File details

Details for the file TimePinner-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: TimePinner-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for TimePinner-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b00b5130b32f5f70bb43297a41a79085aad63dfc5000440269c0d0d145f85598
MD5 8cdb08e7ceea36af329f36033cedfc02
BLAKE2b-256 6d77b6e7cf89fdf4c95ea2ccf72c4002107b6f3f69b62f61b502a71d52082f06

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page