TimePinner


NameTimePinner JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://gitee.com/g1879/TimePinner
Summary一个用于代码中计时的小工具。
upload_time2023-01-14 16:39:02
maintainer
docs_urlNone
authorg1879
requires_python>=3.6
licenseMIT
keywords stopwatch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 简介

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

类似于代码中的秒表。

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

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

# 安装与导入

## 安装

```python
pip install TimePinner
```

## 导入

```python
from TimePinner import Pinner
```

# 使用方法

## 创建对象

```python
from TimePinner import Pinner

pinner = Pinner()
```

## 记录时间点

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

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

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

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

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

输出:

```console
0.0
记录1:1.0084643
```

## 跳过时间段

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

```python
pinner.skip()
```

## 打印结果

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

```console
记录1:1.007383
记录2:2.0145351000000002
```

## 获取结果

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

```python
print(pinner.records)
```

输出:

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

## 获取最短的时间段

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

```python
print(pinner.winner)
```

输出:

```console
('记录1', 1.0084643)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitee.com/g1879/TimePinner",
    "name": "TimePinner",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "stopwatch",
    "author": "g1879",
    "author_email": "g1879@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/6b/ce/b8de139ada94308ea0e1e98cc55f899e2fdd91e11cfef09776b7560bb008/TimePinner-0.1.1.tar.gz",
    "platform": null,
    "description": "# \u7b80\u4ecb\r\n\r\nTimePinner \u662f\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u65f6\u5de5\u5177\u3002\r\n\r\n\u7c7b\u4f3c\u4e8e\u4ee3\u7801\u4e2d\u7684\u79d2\u8868\u3002\r\n\r\n\u53ef\u6807\u8bb0\u591a\u4e2a\u70b9\uff0c\u4ee5\u8bb0\u5f55\u82e5\u5e72\u6bb5\u65f6\u95f4\u957f\u5ea6\u3002\r\n\r\n\u6bcf\u6bb5\u65f6\u95f4\u53ef\u4ee5\u547d\u540d\uff0c\u4ee5\u65b9\u4fbf\u8bb0\u5fc6\uff0c\u4e5f\u53ef\u8df3\u8fc7\u65e0\u987b\u8bb0\u5f55\u7684\u65f6\u95f4\u6bb5\u3002\r\n\r\n# \u5b89\u88c5\u4e0e\u5bfc\u5165\r\n\r\n## \u5b89\u88c5\r\n\r\n```python\r\npip install TimePinner\r\n```\r\n\r\n## \u5bfc\u5165\r\n\r\n```python\r\nfrom TimePinner import Pinner\r\n```\r\n\r\n# \u4f7f\u7528\u65b9\u6cd5\r\n\r\n## \u521b\u5efa\u5bf9\u8c61\r\n\r\n```python\r\nfrom TimePinner import Pinner\r\n\r\npinner = Pinner()\r\n```\r\n\r\n## \u8bb0\u5f55\u65f6\u95f4\u70b9\r\n\r\n\u4f7f\u7528`pin()`\u65b9\u6cd5\u8bb0\u5f55\u4e00\u4e2a\u65f6\u95f4\u70b9\uff0c\u53ef\u4ee5\u901a\u8fc7`text`\u53c2\u6570\u7ed9\u8be5\u65f6\u95f4\u70b9\u547d\u540d\u3002\r\n\r\n\u8bb0\u5f55\u7684\u65f6\u5019\u4f1a\u628a\u5f53\u524d\u65f6\u95f4\u6bb5\u6253\u5370\u51fa\u6765\uff0c\u53ef\u7528`show()`\u53c2\u6570\u8bbe\u7f6e\u4e0d\u6253\u5370\u3002\r\n\r\n\u4e5f\u53ef\u4ee5\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u7528`show_everytime`\u53c2\u6570\u8bbe\u7f6e\u662f\u5426\u6253\u5370\u3002\r\n\r\n`pin()`\u7684`show`\u53c2\u6570\u6bd4\u521b\u5efa\u5bf9\u8c61\u65f6`show_everytime`\u53c2\u6570\u4f18\u5148\u7ea7\u9ad8\u3002\r\n\r\n```python\r\npinner = Pinner()\r\npinner.pin()  # \u8bb0\u5f55\u8d77\u59cb\u70b9\r\nsleep(1)\r\npinner.pin('\u8bb0\u5f551')\r\nsleep(2)\r\npinner.pin('\u8bb0\u5f552', show=False)  # \u4e0d\u6253\u5370\u8be5\u8282\u70b9\r\n```\r\n\r\n\u8f93\u51fa\uff1a\r\n\r\n```console\r\n0.0\r\n\u8bb0\u5f551\uff1a1.0084643\r\n```\r\n\r\n## \u8df3\u8fc7\u65f6\u95f4\u6bb5\r\n\r\n\u6709\u4e9b\u65f6\u95f4\u6bb5\u65e0\u987b\u8bb0\u5f55\uff0c\u7528`skip()`\u65b9\u6cd5\u8df3\u8fc7\u3002\u4e0b\u4e00\u4e2a\u8bb0\u5f55\u4f1a\u4ee5\u5f53\u524d\u70b9\u4f5c\u4e3a\u8d77\u59cb\u3002\r\n\r\n```python\r\npinner.skip()\r\n```\r\n\r\n## \u6253\u5370\u7ed3\u679c\r\n\r\n\u901a\u8fc7`show()`\u65b9\u6cd5\uff0c\u53ef\u4ee5\u628a\u8bb0\u5f55\u5230\u7684\u65f6\u95f4\u6bb5\u6253\u5370\u51fa\u6765\u3002\r\n\r\n```console\r\n\u8bb0\u5f551\uff1a1.007383\r\n\u8bb0\u5f552\uff1a2.0145351000000002\r\n```\r\n\r\n## \u83b7\u53d6\u7ed3\u679c\r\n\r\n\u901a\u8fc7`records`\u5c5e\u6027\u83b7\u53d6\u5404\u4e2a\u8bb0\u5f55\u7684\u65f6\u95f4\u6bb5\uff0c\u6bcf\u4e2a\u65f6\u95f4\u6bb5\u4e3a\u4e00\u4e2a\u4e24\u4f4d\u5143\u7ec4\u3002\r\n\r\n```python\r\nprint(pinner.records)\r\n```\r\n\r\n\u8f93\u51fa\uff1a\r\n\r\n```console\r\n[('\u8bb0\u5f551', 1.0084643), ('\u8bb0\u5f552', 2.0126551999999998)]\r\n```\r\n\r\n## \u83b7\u53d6\u6700\u77ed\u7684\u65f6\u95f4\u6bb5\r\n\r\n\u901a\u8fc7`winner`\u5c5e\u6027\u53ef\u4ee5\u83b7\u53d6\u6700\u77ed\u7684\u65f6\u95f4\u6bb5\uff0c\u7528\u4e8e\u5bf9\u6bd4\u51e0\u6bb5\u4ee3\u7801\u8fd0\u884c\u65f6\u95f4\u3002\r\n\r\n```python\r\nprint(pinner.winner)\r\n```\r\n\r\n\u8f93\u51fa\uff1a\r\n\r\n```console\r\n('\u8bb0\u5f551', 1.0084643)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u4e00\u4e2a\u7528\u4e8e\u4ee3\u7801\u4e2d\u8ba1\u65f6\u7684\u5c0f\u5de5\u5177\u3002",
    "version": "0.1.1",
    "split_keywords": [
        "stopwatch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d77b6e7cf89fdf4c95ea2ccf72c4002107b6f3f69b62f61b502a71d52082f06",
                "md5": "8cdb08e7ceea36af329f36033cedfc02",
                "sha256": "b00b5130b32f5f70bb43297a41a79085aad63dfc5000440269c0d0d145f85598"
            },
            "downloads": -1,
            "filename": "TimePinner-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8cdb08e7ceea36af329f36033cedfc02",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4113,
            "upload_time": "2023-01-14T16:39:00",
            "upload_time_iso_8601": "2023-01-14T16:39:00.564404Z",
            "url": "https://files.pythonhosted.org/packages/6d/77/b6e7cf89fdf4c95ea2ccf72c4002107b6f3f69b62f61b502a71d52082f06/TimePinner-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6bceb8de139ada94308ea0e1e98cc55f899e2fdd91e11cfef09776b7560bb008",
                "md5": "682e0b635eee005e8be036cb639cb4bd",
                "sha256": "80a126b431a8007748432548f7a8107af777545e55578b60b51cc59804a76d4b"
            },
            "downloads": -1,
            "filename": "TimePinner-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "682e0b635eee005e8be036cb639cb4bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 3780,
            "upload_time": "2023-01-14T16:39:02",
            "upload_time_iso_8601": "2023-01-14T16:39:02.906553Z",
            "url": "https://files.pythonhosted.org/packages/6b/ce/b8de139ada94308ea0e1e98cc55f899e2fdd91e11cfef09776b7560bb008/TimePinner-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-14 16:39:02",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "timepinner"
}
        
Elapsed time: 0.03217s