py-timer


Namepy-timer JSON
Version 1.2.4 PyPI version JSON
download
home_pagehttps://github.com/qfcy/Python/blob/main/timer_tool.py
SummaryA Python timer module, containing class Timer() and decorator function timer(), as well as some useful functions that can be used for performance analysis.一个Python计时器模块, 其中包含Timer()类和timer()装饰器, 以及一些相关的有用函数, 可用于程序性能分析。
upload_time2024-08-12 12:06:36
maintainerNone
docs_urlNone
author七分诚意 qq:3076711200
requires_pythonNone
licenseNone
keywords timer performance analysis 计时器 性能
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            **警告: 由于本模块的名称timer和pywin32库中的timer模块名称冲突,本模块已弃用和停止更新,请安装作者最新版本的timer-tool模块(https://pypi.org/project/timer-tool/)。**

**Warning: Due to a naming conflict with the timer module in the pywin32 library, this module has been deprecated and will no longer be maintained. Please install the author's latest version of module timer-tool (https://pypi.org/project/timer-tool/).**

模块名称 MODULE NAME
====================

::

    timer

简介 DESCRIPTION
================

::

    A Python timer module, containing class Timer() and decorator function timer(), 
    as well as some useful functions that can be used for performance analysis.
    一个Python计时器模块, 其中包含Timer()类和timer()装饰器, 以及一些相关的有用函数, 可用于程序性能分析。

包含的函数和类 Functions & Classes:
===================================

类:

class Timer
"""""""""""
    一个计时器类
    
    start()
        开始计时。此方法在Timer类初始化时会被自动调用。
    
    gettime()
        获取从计时开始到现在的时间。
    
    printtime(fmt_str="用时:{:.8f}秒")
        打印出从计时开始到现在的时间, 也就是获取的值。

函数: 

timer(msg=None, file=sys.stdout, flush=False)::

    一个装饰器, 为某个函数计时 (比使用Timer类更快、更简单)。
    用法:@timer(msg="用时:{time}秒")
    def func(args):
        print("Hello World!")
    
    #或:
    @timer
    def func(args):
        print("Hello World!")

示例代码 EXAMPLES
=================

示例1:

.. code-block:: python

    import timer
    t=timer.Timer() #初始化Timer对象
    do_something()
    t.printtime() #输出执行do_something()所用时间 (也可使用t.gettime()获取所用时间)

示例2:

.. code-block:: python

    #退出with语句时自动打印出所用时间。
    import timer
    with timer.Timer(): #在这里开始计时
        do_something()

示例3:

.. code-block:: python

    # 为某个函数计时
    from timer import timer
    @timer
    def func():
        print("Hello World!")

示例4:

.. code-block:: python

    # 程序精确地延迟一段时间
    from time import sleep
    from timer import sleep as sleep2
    sleep(0.0001)
    sleep2(0.0001)
    # 经测试表明, time模块的sleep()函数与本模块的函数相比, 有明显的延迟

版本 VERSION
============

    1.2.4

    **警告: 由于本模块的名称timer和pywin32库中的timer模块名称冲突,本模块已弃用和停止更新,请安装作者最新版本的timer-tool模块(https://pypi.org/project/timer-tool/)。**

作者 AUTHOR
===========

    七分诚意 qq:3076711200

    作者CSDN主页: https://blog.csdn.net/qfcy\_

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qfcy/Python/blob/main/timer_tool.py",
    "name": "py-timer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "timer, performance, analysis, \u8ba1\u65f6\u5668, \u6027\u80fd",
    "author": "\u4e03\u5206\u8bda\u610f qq:3076711200",
    "author_email": "3076711200@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/fc/cf9d7a77c2e656d9c4b3ce28f6ae78c4728b80dbb79a5def13dd4a98493f/py-timer-1.2.4.tar.gz",
    "platform": null,
    "description": "**\u8b66\u544a: \u7531\u4e8e\u672c\u6a21\u5757\u7684\u540d\u79f0timer\u548cpywin32\u5e93\u4e2d\u7684timer\u6a21\u5757\u540d\u79f0\u51b2\u7a81\uff0c\u672c\u6a21\u5757\u5df2\u5f03\u7528\u548c\u505c\u6b62\u66f4\u65b0\uff0c\u8bf7\u5b89\u88c5\u4f5c\u8005\u6700\u65b0\u7248\u672c\u7684timer-tool\u6a21\u5757\uff08https://pypi.org/project/timer-tool/\uff09\u3002**\r\n\r\n**Warning: Due to a naming conflict with the timer module in the pywin32 library, this module has been deprecated and will no longer be maintained. Please install the author's latest version of module timer-tool (https://pypi.org/project/timer-tool/).**\r\n\r\n\u6a21\u5757\u540d\u79f0 MODULE NAME\r\n====================\r\n\r\n::\r\n\r\n    timer\r\n\r\n\u7b80\u4ecb DESCRIPTION\r\n================\r\n\r\n::\r\n\r\n    A Python timer module, containing class Timer() and decorator function timer(), \r\n    as well as some useful functions that can be used for performance analysis.\r\n    \u4e00\u4e2aPython\u8ba1\u65f6\u5668\u6a21\u5757, \u5176\u4e2d\u5305\u542bTimer()\u7c7b\u548ctimer()\u88c5\u9970\u5668, \u4ee5\u53ca\u4e00\u4e9b\u76f8\u5173\u7684\u6709\u7528\u51fd\u6570, \u53ef\u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002\r\n\r\n\u5305\u542b\u7684\u51fd\u6570\u548c\u7c7b Functions & Classes:\r\n===================================\r\n\r\n\u7c7b:\r\n\r\nclass Timer\r\n\"\"\"\"\"\"\"\"\"\"\"\r\n    \u4e00\u4e2a\u8ba1\u65f6\u5668\u7c7b\r\n    \r\n    start()\r\n        \u5f00\u59cb\u8ba1\u65f6\u3002\u6b64\u65b9\u6cd5\u5728Timer\u7c7b\u521d\u59cb\u5316\u65f6\u4f1a\u88ab\u81ea\u52a8\u8c03\u7528\u3002\r\n    \r\n    gettime()\r\n        \u83b7\u53d6\u4ece\u8ba1\u65f6\u5f00\u59cb\u5230\u73b0\u5728\u7684\u65f6\u95f4\u3002\r\n    \r\n    printtime(fmt_str=\"\u7528\u65f6:{:.8f}\u79d2\")\r\n        \u6253\u5370\u51fa\u4ece\u8ba1\u65f6\u5f00\u59cb\u5230\u73b0\u5728\u7684\u65f6\u95f4, \u4e5f\u5c31\u662f\u83b7\u53d6\u7684\u503c\u3002\r\n\r\n\u51fd\u6570: \r\n\r\ntimer(msg=None, file=sys.stdout, flush=False)::\r\n\r\n    \u4e00\u4e2a\u88c5\u9970\u5668, \u4e3a\u67d0\u4e2a\u51fd\u6570\u8ba1\u65f6 (\u6bd4\u4f7f\u7528Timer\u7c7b\u66f4\u5feb\u3001\u66f4\u7b80\u5355)\u3002\r\n    \u7528\u6cd5:@timer(msg=\"\u7528\u65f6:{time}\u79d2\")\r\n    def func(args):\r\n        print(\"Hello World!\")\r\n    \r\n    #\u6216:\r\n    @timer\r\n    def func(args):\r\n        print(\"Hello World!\")\r\n\r\n\u793a\u4f8b\u4ee3\u7801 EXAMPLES\r\n=================\r\n\r\n\u793a\u4f8b1:\r\n\r\n.. code-block:: python\r\n\r\n    import timer\r\n    t=timer.Timer() #\u521d\u59cb\u5316Timer\u5bf9\u8c61\r\n    do_something()\r\n    t.printtime() #\u8f93\u51fa\u6267\u884cdo_something()\u6240\u7528\u65f6\u95f4 (\u4e5f\u53ef\u4f7f\u7528t.gettime()\u83b7\u53d6\u6240\u7528\u65f6\u95f4)\r\n\r\n\u793a\u4f8b2:\r\n\r\n.. code-block:: python\r\n\r\n    #\u9000\u51fawith\u8bed\u53e5\u65f6\u81ea\u52a8\u6253\u5370\u51fa\u6240\u7528\u65f6\u95f4\u3002\r\n    import timer\r\n    with timer.Timer(): #\u5728\u8fd9\u91cc\u5f00\u59cb\u8ba1\u65f6\r\n        do_something()\r\n\r\n\u793a\u4f8b3:\r\n\r\n.. code-block:: python\r\n\r\n    # \u4e3a\u67d0\u4e2a\u51fd\u6570\u8ba1\u65f6\r\n    from timer import timer\r\n    @timer\r\n    def func():\r\n        print(\"Hello World!\")\r\n\r\n\u793a\u4f8b4:\r\n\r\n.. code-block:: python\r\n\r\n    # \u7a0b\u5e8f\u7cbe\u786e\u5730\u5ef6\u8fdf\u4e00\u6bb5\u65f6\u95f4\r\n    from time import sleep\r\n    from timer import sleep as sleep2\r\n    sleep(0.0001)\r\n    sleep2(0.0001)\r\n    # \u7ecf\u6d4b\u8bd5\u8868\u660e, time\u6a21\u5757\u7684sleep()\u51fd\u6570\u4e0e\u672c\u6a21\u5757\u7684\u51fd\u6570\u76f8\u6bd4, \u6709\u660e\u663e\u7684\u5ef6\u8fdf\r\n\r\n\u7248\u672c VERSION\r\n============\r\n\r\n    1.2.4\r\n\r\n    **\u8b66\u544a: \u7531\u4e8e\u672c\u6a21\u5757\u7684\u540d\u79f0timer\u548cpywin32\u5e93\u4e2d\u7684timer\u6a21\u5757\u540d\u79f0\u51b2\u7a81\uff0c\u672c\u6a21\u5757\u5df2\u5f03\u7528\u548c\u505c\u6b62\u66f4\u65b0\uff0c\u8bf7\u5b89\u88c5\u4f5c\u8005\u6700\u65b0\u7248\u672c\u7684timer-tool\u6a21\u5757\uff08https://pypi.org/project/timer-tool/\uff09\u3002**\r\n\r\n\u4f5c\u8005 AUTHOR\r\n===========\r\n\r\n    \u4e03\u5206\u8bda\u610f qq:3076711200\r\n\r\n    \u4f5c\u8005CSDN\u4e3b\u9875: https://blog.csdn.net/qfcy\\_\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python timer module, containing class Timer() and decorator function timer(), as well as some useful functions that can be used for performance analysis.\u4e00\u4e2aPython\u8ba1\u65f6\u5668\u6a21\u5757, \u5176\u4e2d\u5305\u542bTimer()\u7c7b\u548ctimer()\u88c5\u9970\u5668, \u4ee5\u53ca\u4e00\u4e9b\u76f8\u5173\u7684\u6709\u7528\u51fd\u6570, \u53ef\u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002",
    "version": "1.2.4",
    "project_urls": {
        "Homepage": "https://github.com/qfcy/Python/blob/main/timer_tool.py"
    },
    "split_keywords": [
        "timer",
        " performance",
        " analysis",
        " \u8ba1\u65f6\u5668",
        " \u6027\u80fd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bfccf9d7a77c2e656d9c4b3ce28f6ae78c4728b80dbb79a5def13dd4a98493f",
                "md5": "b7cc0c4d54b4e47bc548e7e548777a72",
                "sha256": "ef81152b291bd297662f2de8650be3a7b84b12d86bb594e3211271fa99f3436d"
            },
            "downloads": -1,
            "filename": "py-timer-1.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "b7cc0c4d54b4e47bc548e7e548777a72",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15972,
            "upload_time": "2024-08-12T12:06:36",
            "upload_time_iso_8601": "2024-08-12T12:06:36.130897Z",
            "url": "https://files.pythonhosted.org/packages/5b/fc/cf9d7a77c2e656d9c4b3ce28f6ae78c4728b80dbb79a5def13dd4a98493f/py-timer-1.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-12 12:06:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qfcy",
    "github_project": "Python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-timer"
}
        
Elapsed time: 0.26043s